結果

問題 No.812 Change of Class
ユーザー simamumu
提出日時 2019-04-12 22:00:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 842 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 430,156 KB
最終ジャッジ日時 2024-06-12 18:20:14
合計ジャッジ時間 22,389 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other WA * 5 TLE * 1 -- * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,random
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M = inpl()
lines = defaultdict(set)
for i in range(M):
    p,q = inpl()
    p,q = p-1,q-1
    lines[p].add(q)
    lines[q].add(p)

Q = int(input())
for i in range(Q):
    A = int(input())
    A -= 1
    q = queue.Queue()

    q.put([A,0])
    link = [0]*N
    tmp = 0
    while not q.empty():
        s,depth = q.get()
        if link[s] == 0:
            link[s] = 1
            for t in lines[s]:
                q.put([t,depth+1])
            tmp = max(tmp,depth)
    if tmp <= 1:
        print(sum(link)-1,0)
    else:
        print(sum(link)-1,(tmp+1)//2)
0