-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2606.cpp
More file actions
58 lines (47 loc) · 904 Bytes
/
2606.cpp
File metadata and controls
58 lines (47 loc) · 904 Bytes
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
/**
* @file 2606.cpp
* @brief 바이러스
* @author Sam Kim (samkim2626@gmail.com)
*/
#include <iostream>
#include <deque>
using namespace std;
int n, m;
int comp[101][101] = {0};
bool visited[101];
int cnt = 0;
void bfs(int start)
{
deque<int> dq;
dq.push_back(start);
visited[start] = true;
while (!dq.empty())
{
int v = dq.front();
dq.pop_front();
cnt++;
for (int i = 1; i <= n; i++)
{
if (comp[v][i] == 1 && visited[i] != true)
{
dq.push_back(i);
visited[i] = true;
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
comp[a][b] = comp[b][a] = 1;
}
bfs(1);
cout << cnt - 1 << '\n';
return 0;
}