반응형
https://www.acmicpc.net/problem/2606
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
|
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int N;
int my_pair;
int main(void) {
cin >> N;
cin >> my_pair;
vector <bool> check(N,false);
vector <pair<int,int> > v;
queue<int> q;
pair<int, int> pair_tmp;
check[0] = true;
for (int i = 0;i < my_pair;i++) {
v.push_back(pair_tmp);
//Queue 에넣기
q.push(pair_tmp.second);
}
q.push(pair_tmp.first);
}
}
while (!q.empty()) {
int target = q.front();
//cout << target << endl;
q.pop();
check[target - 1] = true;
for (int i = 0;i <my_pair;i++) {
if (v[i].first == target && check[v[i].second -1]==false) {
q.push(v[i].second);
}
else if (v[i].second == target && check[v[i].first -1]==false) {
q.push(v[i].first);
}
}
}
int cnt = 0;
for (int i = 0;i < check.size();++i) {
if (check[i] == true) ++cnt;
}
cout << cnt-1;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형