-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2606.cpp
48 lines (42 loc) · 926 Bytes
/
2606.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int visited[101];
vector<int>networks[101];
void findRoute(int start) {
queue<int> q;
q.push(start);
visited[start] = true;
while(!q.empty()) {
int now = q.front();
q.pop();
for(int i=0;i<networks[now].size();i++) {
int nextCom = networks[now][i];
if(visited[nextCom] == false) {
q.push(nextCom);
visited[nextCom] = true;
}
}
}
}
int main()
{
int n, m;
cin>> n >> m;
for(int i=0;i<m;i++) {
int first, second;
cin >> first >> second;
networks[first].push_back(second);
networks[second].push_back(first);
}
findRoute(1);
int count = 0;
for(int i=2;i<=n;i++) {
if(visited[i] == true) {
count++;
}
}
cout << count;
return 0;
}