結果

問題 No.812 Change of Class
ユーザー stng
提出日時 2022-07-06 17:48:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,032 ms / 4,000 ms
コード長 904 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,012 KB
実行使用メモリ 161,412 KB
最終ジャッジ日時 2024-12-22 22:38:51
合計ジャッジ時間 24,521 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import bisect
n,m = map(int,input().split())
pq = [[] for i in range(n)]
for i in range(m):
    p,q = map(int,input().split())
    p -= 1
    q -= 1
    pq[p].append(q)
    pq[q].append(p)

q = int(input())
a = [int(input())-1 for i in range(q)]

ans = []
rui = [2**i for i in range(20)]
#idx = bisect.bisect_left(cnt,8)
#print(cnt)
#print(idx)

for i in range(q):
    chk = [0]*n
    chk[a[i]] = 1
    d = deque()
    d.append([a[i],0])
    mcnt = 0
    while len(d) > 0:
        tmp,cnt = d.popleft()
        for j in pq[tmp]:
            if chk[j] == 0:
                chk[j] = 1
                d.append([j,cnt+1])
                mcnt = cnt+1
    if mcnt == 0:
        ans.append([0,0])
    else:
        idx = bisect.bisect_left(rui,mcnt)
        #ans.append([sum(chk)-1,(mcnt+1)//2])
        ans.append([sum(chk)-1,idx])

for i in range(len(ans)):
    print(*ans[i])
0