|
| 1 | +```java |
| 2 | +import java.io.*; |
| 3 | +import java.util.*; |
| 4 | +public class Main { |
| 5 | + |
| 6 | + static final int INF = 50; |
| 7 | + public static void main(String[] args) throws IOException { |
| 8 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 9 | + |
| 10 | + // 입력 |
| 11 | + int n = Integer.parseInt(br.readLine()); |
| 12 | + |
| 13 | + int[][] dist = new int[n+1][n+1]; |
| 14 | + for (int i = 1; i < n+1; i++) { |
| 15 | + for (int j = 1; j < n+1; j++) { |
| 16 | + if (i == j) { |
| 17 | + continue; |
| 18 | + } |
| 19 | + dist[i][j] = INF; |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + while (true) { |
| 24 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 25 | + int u = Integer.parseInt(st.nextToken()); |
| 26 | + int v = Integer.parseInt(st.nextToken()); |
| 27 | + if (u == -1 && v == -1) { break; } |
| 28 | + dist[u][v] = 1; |
| 29 | + dist[v][u] = 1; |
| 30 | + } |
| 31 | + |
| 32 | + // 풀이 |
| 33 | + for (int mid = 1; mid < n+1; mid++) { |
| 34 | + for (int i = 1; i < n+1; i++) { |
| 35 | + for (int j = 1; j < n+1; j++) { |
| 36 | + if (i == j) { continue; } |
| 37 | + dist[i][j] = Integer.min(dist[i][j], dist[i][mid] + dist[mid][j]); |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + int[] score = new int[n+1]; |
| 43 | + for (int i = 1; i < n+1; i++) { |
| 44 | + score[i] = Arrays.stream(dist[i]).max().getAsInt(); |
| 45 | + } |
| 46 | + int minScore = INF; |
| 47 | + int count = 0; |
| 48 | + for (int i = 1; i < n+1; i++) { |
| 49 | + if (score[i] < minScore) { |
| 50 | + minScore = score[i]; |
| 51 | + count = 1; |
| 52 | + } else if (score[i] == minScore) { |
| 53 | + count++; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + // 출력 |
| 58 | + System.out.println(minScore + " " + count); |
| 59 | + for (int i = 1; i < n+1; i++) { |
| 60 | + if (score[i] == minScore) { |
| 61 | + System.out.print(i + " "); |
| 62 | + } |
| 63 | + } |
| 64 | + System.out.println(); |
| 65 | + |
| 66 | + br.close(); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +``` |
0 commit comments