-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_10159.cpp
More file actions
70 lines (60 loc) · 1.27 KB
/
BOJ_10159.cpp
File metadata and controls
70 lines (60 loc) · 1.27 KB
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
// 21/11/04
#include <iostream>
#include <vector>
using namespace std;
int n, m;
vector<vector<int>> edge_up;
vector<vector<int>> edge_down;
void Input(void)
{
cin >> n >> m;
edge_up.assign(n+1, vector<int>(0,0));
edge_down.assign(n+1, vector<int>(0,0));
while (m--)
{
int a, b;
cin >> a >> b;
edge_down[a].push_back(b);
edge_up[b].push_back(a);
}
}
void Search_up(int i, vector<bool>&check)
{
for (auto iter = edge_up[i].begin(); iter!=edge_up[i].end(); iter++)
{
if (check[*iter])
continue;
check[*iter] = true;
Search_up(*iter, check);
}
}
void Search_down(int i, vector<bool>&check)
{
for (auto iter = edge_down[i].begin(); iter!=edge_down[i].end(); iter++)
{
if (check[*iter])
continue;
check[*iter] = true;
Search_down(*iter, check);
}
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
Input();
for (int i=1; i<=n; i++)
{
vector<bool> check(n+1, false);
Search_up(i, check);
Search_down(i, check);
int answer = 0;
for (int j=1; j<=n; j++)
{
if (!check[j])
answer++;
}
cout << answer-1 <<"\n";
}
return 0;
}