Skip to content

Commit 376fe03

Browse files
authored
Merge pull request #460 from AlgorithmWithGod/JHLEE325
[20250714] BOJ / G4 / 저울 / 이준희
2 parents cdd79e1 + 08e90ba commit 376fe03

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
```

0 commit comments

Comments
 (0)