-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17616.cpp
More file actions
49 lines (41 loc) · 878 Bytes
/
17616.cpp
File metadata and controls
49 lines (41 loc) · 878 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
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
using namespace std;
const ll INF = 1e9 + 7;
const ll DIV = 987654321;
int n, m, x;
vector<int> adj[101010], radj[101010];
bool vst[101010];
int dfs1(int cur){
vst[cur] = 1;
int ret = 1;
for(int i : adj[cur]){
if(!vst[i]) ret += dfs1(i);
}
return ret;
}
int dfs2(int cur){
vst[cur] = 1;
int ret = 1;
for(int i : radj[cur]){
if(!vst[i]) ret += dfs2(i);
}
return ret;
}
int main()
{
fastio;
cin >> n>> m >> x;
for(int i =0 ;i < m;i++){
int a, b;
cin >> a>> b;
adj[a].push_back(b);
radj[b].push_back(a);
}
int bk = dfs1(x) - 1;
memset(vst, 0 ,sizeof vst);
int fr = dfs2(x) - 1;
cout << fr + 1 << " " << (n - bk) << "\n";
return 0;
}