Skip to content

Commit 309859a

Browse files
authored
Merge pull request #961 from AlgorithmWithGod/zinnnn37
[20250923] BOJ / G5 / 회장뽑기 / 김민진
2 parents 6d8e841 + bd9032a commit 309859a

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
```java
2+
import java.io.*;
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.StringTokenizer;
6+
7+
public class BJ_2660_회장뽑기 {
8+
9+
private static final int INF = 987654321;
10+
11+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
13+
private static final StringBuilder sb = new StringBuilder();
14+
private static StringTokenizer st;
15+
16+
private static int N;
17+
private static int[][] graph;
18+
private static List<Integer> candidate;
19+
20+
public static void main(String[] args) throws IOException {
21+
init();
22+
sol();
23+
}
24+
25+
private static void init() throws IOException {
26+
N = Integer.parseInt(br.readLine());
27+
28+
graph = new int[N + 1][N + 1];
29+
for (int i = 1; i <= N; i++) {
30+
for (int j = 1; j <= N; j++) {
31+
if (i == j) continue;
32+
graph[i][j] = INF;
33+
}
34+
}
35+
36+
candidate = new ArrayList<>();
37+
while (true) {
38+
st = new StringTokenizer(br.readLine());
39+
40+
int u = Integer.parseInt(st.nextToken());
41+
int v = Integer.parseInt(st.nextToken());
42+
43+
if (u == -1 && v == -1) break;
44+
45+
graph[u][v] = 1;
46+
graph[v][u] = 1;
47+
}
48+
}
49+
50+
private static void sol() throws IOException {
51+
for (int k = 1; k <= N; k++) {
52+
for (int i = 1; i <= N; i++) {
53+
for (int j = 1; j <= N; j++) {
54+
if (i == j || i == k || j == k) continue;
55+
56+
if (graph[i][j] > graph[i][k] + graph[k][j]) {
57+
graph[i][j] = graph[i][k] + graph[k][j];
58+
}
59+
}
60+
}
61+
}
62+
63+
int tmp = INF;
64+
for (int i = 1; i <= N; i++) {
65+
int max = 0;
66+
for (int j = 1; j <= N; j++) {
67+
if (graph[i][j] == INF) continue;
68+
69+
max = Math.max(graph[i][j], max);
70+
}
71+
72+
if (max == tmp) {
73+
candidate.add(i);
74+
} else if (max < tmp) {
75+
tmp = max;
76+
candidate.clear();
77+
candidate.add(i);
78+
}
79+
}
80+
81+
sb.append(tmp).append(" ").append(candidate.size()).append("\n");
82+
for (int i : candidate) {
83+
sb.append(i).append(" ");
84+
}
85+
bw.write(sb.toString());
86+
bw.flush();
87+
bw.close();
88+
br.close();
89+
}
90+
91+
}
92+
```

0 commit comments

Comments
 (0)