File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+
3+ import java.util.* ;
4+ import java.io.* ;
5+
6+ class Main {
7+
8+ // IO field
9+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
10+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
11+ static StringTokenizer st = new StringTokenizer (" " );
12+
13+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
14+ static String nextToken() throws Exception {
15+ if (! st. hasMoreTokens()) nextLine();
16+ return st. nextToken();
17+ }
18+ static int nextInt() throws Exception { return Integer . parseInt(nextToken()); }
19+ static long nextLong() throws Exception { return Long . parseLong(nextToken()); }
20+ static double nextDouble() throws Exception { return Double . parseDouble(nextToken()); }
21+ static void bwEnd() throws Exception {bw. flush();bw. close();}
22+
23+ // Additional field
24+
25+ static int N , M , X ;
26+ static List<Integer > [] V , E ;
27+ static boolean [] vis;
28+
29+ public static void main(String [] args) throws Exception {
30+
31+ ready();
32+ solve();
33+
34+ bwEnd();
35+
36+ }
37+
38+ static void ready() throws Exception {
39+
40+ N = nextInt();
41+ M = nextInt();
42+ X = nextInt();
43+ V = new List [N + 1 ];
44+ E = new List [N + 1 ];
45+ for (int i= 1 ;i<= N ;i++ ) {
46+ V [i] = new ArrayList<> ();
47+ E [i] = new ArrayList<> ();
48+ }
49+ for (int i= 0 ;i< M ;i++ ) {
50+ int a = nextInt(), b = nextInt();
51+ V [a]. add(b);
52+ E [b]. add(a);
53+ }
54+
55+ }
56+
57+ static void solve() throws Exception {
58+
59+ vis = new boolean [N + 1 ];
60+ int max = N - dfs(V ,X ) + 1 ;
61+ int min = dfs(E ,X );
62+ bw. write(min + " " + max);
63+
64+ }
65+
66+ static int dfs(List<Integer > [] G , int n) {
67+ int res = 0 ;
68+ for (int i: G [n]) if (! vis[i]) {
69+ vis[i] = true ;
70+ res += dfs(G ,i);
71+ }
72+ return res+ 1 ;
73+ }
74+
75+ }
76+
77+ ```
You can’t perform that action at this time.
0 commit comments