当前位置:网站首页>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;
}
边栏推荐
- In the next bull market, can platofarm, the leading project in the Web3 world, set foot on the top of the mountain
- Detailed explanation of wechat applet page configuration and sitemap configuration parameters
- 「题解」蝙蝠侠的麻烦
- Move protocol launched a beta version, and you can "0" participate in p2e
- 33 introduction to sparksql, dataframe and dataset
- Error reported by Nacos: error Nacos failed to start, please see d:\nacos\logs\nacos log for more details.
- Enterprises love hybrid app development, and applet container technology can improve efficiency by 100%
- [wechat applet development] (II) wechat native bottom tabbar configuration
- 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)
- Arrays and linked lists
猜你喜欢

Wei Xiaoli's "pursuer" is coming

About the big hole of wechat applet promise

Digital collections "chaos", 100 billion market changes are coming?

JSON extractor use in JMeter

「题解」带分数

2022.7.11全盘题解

Play to earn: a new and more promising game paradigm in the future

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

Web3 traffic aggregation platform starfish OS interprets the "p2e" ecosystem of real business

Bit.store, which has attracted much attention, is at a glance of the latest developments
随机推荐
[multithreading] five communication modes between multithreads
Shared lock, exclusive lock, mutex lock, pessimistic lock, optimistic lock, row lock, table lock, page lock, non repeatable read, lost modification, read dirty data
Kotin fragment the correct way to get ViewModel instances
Alibaba cloud deploys SSL certificates
Web3 traffic aggregation platform starfish OS interprets the "p2e" ecosystem of real business
Private traffic + apps, new opportunities for e-commerce drainage
dba
js获取当前浏览器的默认语言
Move protocol starts with running and builds a healthy ecosystem of sports
Introduction of some functions or methods in DGL Library
[linear algebra] deeply understand matrix multiplication, symmetric matrix, positive definite matrix
栈/堆/队列刷题(下)
「题解」带分数
[wechat applet development (II)] custom navigation bar
图的认识与存储
[wechat applet development] (II) wechat native bottom tabbar configuration
[Game Collection] mobile phones are about to burst, and a collection of six high-quality pyGame games is coming ~ (source code attached)
Advantages and disadvantages of redis and ZK implementing distributed locks
「题解」蝙蝠侠的麻烦
Install SQL Server database