当前位置:网站首页>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;
}
边栏推荐
- MySQL date formatting
- DGL库中一些函数或者方法的介绍
- SIFT feature point extraction
- Several development frameworks based on openresty
- Svg from entry to regret, why not learn it earlier (graphic version)
- Private traffic + apps, new opportunities for e-commerce drainage
- [multithreading] five communication modes between multithreads
- [wechat applet development (IV)] applet fast actual combat classic problem navigation
- Okaleido tiger NFT is about to log in to binance NFT platform, and the era of NFT rights and interests is about to start
- "Move to earn" motion metauniverse, move starts a new journey
猜你喜欢

Will Plato become the risk target of the meta universe? Platofarm has great opportunities
![[wechat applet development] (I) development environment and applet official account application](/img/94/b93d5fb6d9e3515a1f218cc4ec6eef.png)
[wechat applet development] (I) development environment and applet official account application
![[wechat applet development] (IV) uni app from getting started to giving up](/img/ed/03e4db18aa5705d38ec17ef982b0c7.png)
[wechat applet development] (IV) uni app from getting started to giving up
![[Game Collection] mobile phones are about to burst, and a collection of six high-quality pyGame games is coming ~ (source code attached)](/img/9e/b237bfa891bd2beb9c1b8a612e9090.png)
[Game Collection] mobile phones are about to burst, and a collection of six high-quality pyGame games is coming ~ (source code attached)

Wechat payment V3 version of openresty implementation and pit avoidance Guide (service side)
![[MySQL] installation tutorial and master-slave configuration](/img/79/0ad3f68b69a0a03a62422d4cc70035.png)
[MySQL] installation tutorial and master-slave configuration

国产“火箭心”人工心脏上市 不同人工心脏有什么区别?
![[redis] how much do you know about bloom filter and cuckoo filter?](/img/f0/8bcbe82bd6d412e68d85450f5894e3.png)
[redis] how much do you know about bloom filter and cuckoo filter?

Enterprises love hybrid app development, and applet container technology can improve efficiency by 100%

SVG 从入门到后悔,怎么不早点学起来(图解版)
随机推荐
In the next bull market, can platofarm, the leading project in the Web3 world, set foot on the top of the mountain
[MySQL] 08: aggregate function
What is the difference between domestic "rocket heart" artificial heart and different artificial heart?
Kotlin higher order function & DSL layout persuasion Guide
[shutter] the shutter doctor reports an error
Kotlin coprocess analysis (III) -- understanding the context of coprocess
【MySQL】08:聚合函数
How to write your FAQ page?
Kotlin coroutine (II): scope and cancellation
Summary of points management system project
图的认识与存储
Shared lock, exclusive lock, mutex lock, pessimistic lock, optimistic lock, row lock, table lock, page lock, non repeatable read, lost modification, read dirty data
Ansible automatic operation and maintenance
Uva572 oil deposits problem solution
Digital collections "chaos", 100 billion market changes are coming?
[linear algebra] deeply understand matrix multiplication, symmetric matrix, positive definite matrix
Figure New Earth: how the RVT format BIM model modeled by Revit can accurately match the map with texture
赛宁TechTalk丨攻防演练:攻击组合拳 “稳准狠”渗透
Saining Techtalk attack and defense drill: attack combination fist "stable, accurate and ruthless" penetration
Move protocol global health declaration, step into Web3 in sports