forked from b-chae/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2606.cpp
More file actions
57 lines (45 loc) · 800 Bytes
/
Copy path2606.cpp
File metadata and controls
57 lines (45 loc) · 800 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
#include <iostream>
#include <vector>
#include <list>
using namespace std;
typedef struct node {
bool visited;
list<int> next;
};
int N, K;
list<int> bfsQueue;
vector<node> Node;
int bfs() {
if (bfsQueue.empty()) return 0;
int count = 0;
int x = bfsQueue.front();
bfsQueue.pop_front();
for (int i : Node[x].next) {
if (!Node[i].visited) {
count++;
Node[i].visited = true;
bfsQueue.push_back(i);
}
}
return count + bfs();
}
int main()
{
int i;
cin >> N >> K;
for (i = 0; i < N+1; i++) {
node new_node;
new_node.visited = false;
Node.push_back(new_node);
}
for (i = 0; i < K; i++) {
int x, y;
cin >> x >> y;
Node[x].next.push_back(y);
Node[y].next.push_back(x);
}
Node[1].visited = true;
bfsQueue.push_back(1);
int ans = bfs();
cout << ans;
}