-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2606.cpp
71 lines (41 loc) · 966 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
#include <string>
using namespace std;
int n;
int m;
int temp;
bool infected[101];
bool connected[101][101];
int currentcounting = 0;
int temp1;
int maxi = 0;
int qsize = 0;
void bfs(int startc){
queue<int> q;
q.push(startc);
infected[startc] = true;
while(!q.empty()){
int comp = q.front();
q.pop();
for(int i = 1; i < n + 1; i++){
if(connected[comp][i] == true && infected[i] != true){
q.push({i});
infected[i] = true;
currentcounting++;
}
}
}
cout << currentcounting;
}
int main(){
cin >> n;
cin >> m;
int i;
for(i = 0; i < m; i++){
cin >> temp;
cin >> temp1;
connected[temp][temp1] = true;
connected[temp1][temp] = true;
}
bfs(1);
}