-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ10159.java
More file actions
43 lines (36 loc) · 1.2 KB
/
Copy pathJ10159.java
File metadata and controls
43 lines (36 loc) · 1.2 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
package TIL;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class J10159 {
public static void main(String[] args) throws IOException {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(buffer.readLine());
int m = Integer.parseInt(buffer.readLine());
boolean arr[][] = new boolean[n+1][n+1];
for(int j = 0; j<m; j++){
String[] input = buffer.readLine().split(" ");
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[1]);
arr[a][b] = true;
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(arr[i][k] && arr[k][j])
arr[i][j] = true;
}
}
}
int cnt =0;
for(int i =1; i<=n; i++){
cnt = 0;
for(int j =1; j<=n; j++){
if (i != j && (arr[i][j] || arr[j][i])) {
cnt++;
}
}
System.out.println(n-1-cnt);
}
}
}