結果

問題 No.812 Change of Class
ユーザー brthyyjp
提出日時 2022-02-09 16:00:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,239 ms / 4,000 ms
コード長 893 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 102,508 KB
最終ジャッジ日時 2024-06-24 19:50:39
合計ジャッジ時間 26,902 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from collections import deque
import bisect

N = 32
P = [0]*N
P[0] = 1
for i in range(1, N):
    P[i] = P[i-1]*2

n, m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    g[x].append(y)
    g[y].append(x)
q = int(input())
Q = []
for i in range(q):
    a = int(input())
    a -= 1
    Q.append(a)

for a in Q:
    q = deque([])
    q.append(a)
    dist = [-1]*n
    dist[a] = 0
    while q:
        v = q.popleft()
        for u in g[v]:
            if dist[u] != -1:
                continue
            dist[u] = dist[v]+1
            q.append(u)
    cnt = 0
    M = 0
    for i in range(n):
        if dist[i] != -1:
            cnt += 1
            M = max(M, dist[i])
    t = bisect.bisect_left(P, M)
    print(cnt-1, t)
0