当前位置:网站首页>L2-010 row seats (25 points) and check the collection
L2-010 row seats (25 points) and check the collection
2022-04-23 00:36:00 【hys__ handsome】
Topic details - L2-010 Row of seats (25 branch ) (pintia.cn)
One key point is to judge whether two people have common friends , This equivalence is related to whether the graph is connected , Therefore, we use parallel search set to solve the problem
#include<iostream>
using namespace std;
const int N = 110;
int a[N][N],f[N];
int n,m,k;
bool check(int x,int y){
for(int i = 1; i <= n; i++){
if(a[x][i] == 1 && a[y][i] == 1){
return true;
}
}
return false;
}
int getf(int x){
if(x == f[x]) return x;
else return f[x] = getf(f[x]);
}
void merge(int a,int b){
int fa = getf(a);
int fb = getf(b);
if(fa != fb) f[fb] = fa;
}
int main(){
cin>>n>>m>>k;
for(int i = 1; i <= n; i++) f[i] = i;
for(int i = 1; i <= m; i++){
int u,v,w;
cin>>u>>v>>w;
a[u][v] = a[v][u] = w;
if(w == 1){
merge(u,v);
}
}
while(k--){
int x,y;
cin>>x>>y;
if(a[x][y] == 1) puts("No problem");
else if(a[x][y] == 0) puts("OK");
else {
if(getf(x) == getf(y)) puts("OK but...");
else puts("No way");
}
}
return 0;
}
版权声明
本文为[hys__ handsome]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230033479453.html
边栏推荐
- L2-035 完全二叉树的层序遍历 (25 分)
- 洛谷P2241统计方形
- (transfer) how winscp (SSH FTP client) generates the key to log in Linu
- Analytic hierarchy process software operation steps (Yaahp)
- thymeleaf 的templates子集目录下不能引入common公共页面,否则报错:模板解析错误,错误原因:公共页面的引用路径错误(缺少子目录名)
- The addition inverse element (a ^ a = 0) XOR operation, which has no performance advantage, is just an intelligence game
- Application of tidb in massive transactions and real-time analysis of fast food chain enterprises
- Ten years of working at Google is also a happy decade for me
- 深度学习基础学习-RNN与LTSM
- 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目
猜你喜欢

【图像分类】——来来来,干了这碗EfficientNet实战(Pytorch)

多测师杭州拱墅校区肖sir_高级金牌讲师_简历实战

MySQL built-in function

Bypass network restrictions through RDP tunnel

Pain points solved by tidb under the wave of localization

我和TiDB的故事 | 毫无准备地不期而遇,却想说与你相遇好幸运

Simple use of Excel if function

ArcGIS 城市生活区用地适宜性评价(一)
![[classification de l'image] - Venez et séchez ce bol d'efficientnet](/img/74/8c811ba94e29947d5c2ae0e1c05131.png)
[classification de l'image] - Venez et séchez ce bol d'efficientnet

【图像分类】用最简短的代码复现SeNet,小白一定要收藏(keras,Tensorflow2.x)
随机推荐
[play with lighthouse] build a temporary mailbox system that can be collected and destroyed immediately
CAS unified identity authentication (III): external independent configuration
MySQL built-in function
植被物候参数遥感研究进展(好文分享)
JVM performance tuning 1
对Indexlookup的理解误区
L2-022 重排链表 (25 分) 链表操作
L2-010 排座位 (25 分) 并查集
L2-023 图着色问题 (25 分)
396. Rotation function / Sword finger offer II 013 Sum of two-dimensional submatrix
(to) excel 2016 does not have enough memory or disk space to open excel
thymeleaf common公共页面不能使用其他页面 (后台传入)相关的值(map,model等待注入的值)
Static and dynamic control nixie tube
Xamarin效果第二十二篇之录音效果
C# 11 对 ref 和 struct 的改进
L2-012 关于堆的判断 (25 分)(字符串bug待解决)
【AI视野·今日Sound 声学论文速览 第四期】Thu, 21 Apr 2022
网线IP配置
Openresty installation and introduction
c#可变参数params的介绍