-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10159.cpp
More file actions
45 lines (40 loc) · 722 Bytes
/
Copy path10159.cpp
File metadata and controls
45 lines (40 loc) · 722 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
#include <iostream>
#include <vector>
using namespace std;
vector<vector<vector<int>>> adj;
vector<bool> visited;
void dfs(int now, int dir, int &cnt)
{
for (int i = 0; i < adj[dir][now].size(); i++)
{
int next = adj[dir][now][i];
if (!visited[next])
{
visited[next] = true;
cnt++;
dfs(next, dir, cnt);
}
}
}
int main()
{
int N, M, a, b;
cin >> N >> M;
adj.assign(2, vector<vector<int>>(N + 1, vector<int>(0, 0)));
while (M--)
{
cin >> a >> b;
adj[0][a].push_back(b);
adj[1][b].push_back(a);
}
for (int i = 1; i <= N; i++)
{
int count = 0;
visited.assign(N + 1, false);
visited[i] = true;
dfs(i, 0, count);
dfs(i, 1, count);
cout << N - count - 1 << endl;
}
return 0;
}