当前位置:网站首页>3587. 连通图(吉林大学考研机试题)
3587. 连通图(吉林大学考研机试题)
2022-07-24 08:25:00 【Ray.C.L】

思路:求连通性可用并查集或者dfs,bfs
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int p[N];
int n, m;
int find(int x){
if(x != p[x]) p[x] = find(p[x]);
return p[x];
}
int main()
{
while(cin >> n >> m){
for(int i = 1; i <= n; i ++) p[i] = i;
while(m --){
int a, b;
cin >> a >> b;
p[find(a)] = find(b);
}
bool res = true;
for(int i = 2; i <= n; i ++)
if(find(i) != find(1)){
res = false;
break;
}
if(res) puts("YES");
else puts("NO");
}
return 0;
}
边栏推荐
- SVG 从入门到后悔,怎么不早点学起来(图解版)
- Encryption market ushers in a new historical cycle. Look at jpex's "stability" and "health"
- 图的认识与存储
- Chinese brands in the historical process
- Is it safe to open an account online in Beijing
- [Game Collection] mobile phones are about to burst, and a collection of six high-quality pyGame games is coming ~ (source code attached)
- MySQL日期格式化
- Kotin fragment the correct way to get ViewModel instances
- 【游戏合集】手机都要被塞爆了,6款优质Pygame游戏合集降临~(附源码)
- MySQL counts the total sales data of each month
猜你喜欢

JMX console unauthorized access vulnerability

国产“火箭心”人工心脏上市 不同人工心脏有什么区别?

Move protocol global health declaration, step into Web3 in sports

From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run

Wechat payment V3 version of openresty implementation and pit avoidance Guide (service side)

Vscode code style notes (vetur)

Wechat applet host environment, applet architecture, concise operation structure

「题解」火神之友

Mysql database advanced

图新地球:如何导入修改了高程基准(椭球)的CAD文件
随机推荐
MySQL uses explain to analyze SQL execution plans to help find performance bottlenecks
DGL库中一些函数或者方法的介绍
「题解」蝙蝠侠的麻烦
dba
SIFT feature point extraction
[multithreading] five communication modes between multithreads
MySQL date formatting
Upload and insert the execle table into the database based on ThinkPHP
Assembly | screen display numbers
Alibaba cloud OSS uploads pictures under folders and encounters pits
[redis] how much do you know about bloom filter and cuckoo filter?
Look at the most influential infrastructure m-dao of Web3 through the current situation of Dao
积分管理系统项目小结
Learn - use do... While loop according to the formula e=1+1/1+ 1/2!+ 1/3!+…+ 1/n! Calculate the value of E (accuracy is 1e-6)
Several development frameworks based on openresty
Wxml template concise tutorial
FPGA综合项目——图像边缘检测系统
Recognition and storage of Graphs
P3916图的遍历 题解
基于thinkphp将execle表格上传并插入数据库