Skip to content

Commit 795877c

Browse files
authored
Merge pull request #586 from AlgorithmWithGod/JHLEE325
[20250801] BOJ / G4 / 키 순서 / 이준희
2 parents 1ce6241 + 405f5b5 commit 795877c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
public static void main(String[] args) throws Exception {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
StringTokenizer st = new StringTokenizer(br.readLine());
10+
11+
int n = Integer.parseInt(st.nextToken());
12+
int m = Integer.parseInt(st.nextToken());
13+
boolean[][] arr = new boolean[n][n];
14+
15+
for (int i = 0; i < m; i++) {
16+
st = new StringTokenizer(br.readLine());
17+
int a = Integer.parseInt(st.nextToken()) - 1;
18+
int b = Integer.parseInt(st.nextToken()) - 1;
19+
arr[a][b] = true;
20+
}
21+
22+
for (int k = 0; k < n; k++) {
23+
for (int i = 0; i < n; i++) {
24+
for (int j = 0; j < n; j++) {
25+
if (arr[i][k] && arr[k][j])
26+
arr[i][j] = true;
27+
}
28+
}
29+
}
30+
31+
int cnt = 0;
32+
for (int i = 0; i < n; i++) {
33+
boolean isknow = true;
34+
for (int j = 0; j < n; j++) {
35+
if (i == j)
36+
continue;
37+
if (!arr[i][j] && !arr[j][i])
38+
isknow = false;
39+
}
40+
if (isknow)
41+
cnt++;
42+
}
43+
44+
System.out.println(cnt);
45+
}
46+
47+
}
48+
49+
```

0 commit comments

Comments
 (0)