当前位置:网站首页>Connected graph (day 72)
Connected graph (day 72)
2022-07-24 03:02:00 【Zhangxueheng】
List of articles
1: subject
Given an undirected graph and all its edges , Determine whether all vertices of the graph are connected .
Input format
The input contains several sets of data .
The first row of each set of data contains two integers n and m, Represents the number of points and edges of an undirected graph .
Next m That's ok , Each line contains two integers x,y, Indication point x Sum point y Connected to a .
The number of the point is from 1 To n.
There may be double edges and self rings in the graph .
Output format
Output one row per group of data , A result , If all the vertices are connected , Output YES, Otherwise output NO.
Data range
The input can contain at most 10 Group data .
1≤n≤1000,
1≤m≤5000,
1≤x,y≤n
sample input :
4 3
1 2
2 3
3 2
3 2
1 2
2 3
sample output :
NO
YES
2: Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int n, m;
int p[N];
int find(int x)
{
if (p[x] != 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;
}
边栏推荐
- PMP preparation experience | good habits, good process, good results
- Make life full of happiness
- 关于Aries框架增删改查-查Demo
- [hdlbits questions] Verilog language (2) vectors
- 动态规划-01背包问题
- Summernote supports custom video upload function
- 攻防世界WEB练习区(view_source、get_post、robots)
- 322. Change
- Zone d'entraînement Web d'attaque et de défense (View source, get Post, robots)
- Customize the default width and height of kindeditor rich text
猜你喜欢

Ugui source code analysis - imaterialmodifier

The implementation in unity determines whether missing or null
![JS when transferring parameters, the incoming string has data; No data when number is passed in; 2[0] is right! Number type data can be subscripted](/img/4e/3d0c25d9579b6d5c00473048dbbd83.png)
JS when transferring parameters, the incoming string has data; No data when number is passed in; 2[0] is right! Number type data can be subscripted

Attack and defense world web practice area (webshell, command_execution, simple_js)

TCP connection principle
![js傳參時傳入 string有數據;傳入 number時沒有數據;2[0]是對的!number類型數據可以取下標](/img/4e/3d0c25d9579b6d5c00473048dbbd83.png)
js傳參時傳入 string有數據;傳入 number時沒有數據;2[0]是對的!number類型數據可以取下標

Doodle icons - a free commercial graffiti style icon library, cute, light and unique

Understand the low code implementation of microservices

LCD1602 - binge 51

Recorded on July 21, 2022
随机推荐
Zone d'entraînement Web d'attaque et de défense (View source, get Post, robots)
PMP first-hand data and information acquisition
ssm的求职招聘系统兼职应聘求职
Redux Usage Summary
[C language] file operation
TCP data transmission and performance
[brother hero July training] day 23: dictionary tree
The next stop of data visualization platform | gifts from domestic open source data visualization datart "super iron powder"
The simple use of ADB command combined with monkey is super detailed
Lcd1602——斌哥51
SSM based blog system [with background management]
Lumberyard game engine of o3de
Unity message push
CMT registration - Google Scholar ID, semantic scholar ID, and DBLP ID
go log包
summernote 字体显示中文
Daily gossip (I)
To forge ahead on a new journey, the city chain science and technology carnival was grandly held in Xiamen
Doodle icons - a free commercial graffiti style icon library, cute, light and unique
Data Lake (XV): spark and iceberg integrate write operations