BOJ - 2660 - 회장뽑기

Updated:

import sys
_INF = 1e10

def solution():
    N = int(sys.stdin.readline())
    dist = [[_INF for _ in range(N)] for _ in range(N)]

    while True:
        u, v = map(int, sys.stdin.readline().split())
        if u == -1 and v == -1: break

        dist[u-1][v-1] = 1
        dist[v-1][u-1] = 1


    for i in range(N):
        dist[i][i] = 0

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dist[i][j] == 1 or dist[i][j] == 0: continue
                elif dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]

    ret = []
    for i in range(N):
        ret.append(max(dist[i]))

    print(min(ret), ret.count(min(ret)))
    for i, v in enumerate(ret):
        if v == min(ret):
            print(i+1, end=' ')

solution()

https://www.acmicpc.net/problem/2660

Categories:

Updated:

Leave a comment