File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.BufferedReader ;
3+ import java.io.IOException ;
4+ import java.io.InputStreamReader ;
5+ import java.util.ArrayDeque ;
6+ import java.util.Queue ;
7+ import java.util.StringTokenizer ;
8+
9+ public class Main {
10+ static Queue<int[]> list = new ArrayDeque<> ();
11+ static int n, m;
12+ static int [][] w;
13+
14+ public static void main (String [] args ) throws IOException {
15+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
16+ StringTokenizer st;
17+
18+ n = Integer . parseInt(br. readLine());
19+ m = Integer . parseInt(br. readLine());
20+
21+ w = new int [n][n];
22+
23+ for (int i = 0 ; i < m; i++ ) {
24+ st = new StringTokenizer (br. readLine());
25+ int big = Integer . parseInt(st. nextToken()) - 1 ;
26+ int small = Integer . parseInt(st. nextToken()) - 1 ;
27+ w[big][small] = 1 ;
28+ w[small][big] = 2 ;
29+ }
30+
31+ for (int k = 0 ; k < n; k++ ) {
32+ for (int i = 0 ; i < n; i++ ) {
33+ for (int j = 0 ; j < n; j++ ) {
34+ if (w[i][k] == 1 && w[k][j] == 1 ) w[i][j] = 1 ;
35+ if (w[i][k] == 2 && w[k][j] == 2 ) w[i][j] = 2 ;
36+ }
37+ }
38+ }
39+
40+ for (int i = 0 ; i < n; i++ ) {
41+ int count = 0 ;
42+ for (int j = 0 ; j < n; j++ ) {
43+ if (i != j && w[i][j] == 0 ) count++ ;
44+ }
45+ System . out. println(count);
46+ }
47+ }
48+
49+
50+ }
51+ ```
You can’t perform that action at this time.
0 commit comments