結果
問題 | No.812 Change of Class |
ユーザー |
![]() |
提出日時 | 2021-03-23 12:23:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 582 ms / 4,000 ms |
コード長 | 635 bytes |
コンパイル時間 | 207 ms |
コンパイル使用メモリ | 82,116 KB |
実行使用メモリ | 106,736 KB |
最終ジャッジ日時 | 2024-11-25 04:30:11 |
合計ジャッジ時間 | 16,845 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 60 |
ソースコード
from collections import dequedef dfs(g,x):q = deque()q.append(x)dist = [-1]*ndist[x] = 0cnt = 0while q:v = q.popleft()for c in g[v]:if dist[c] == -1:dist[c] = dist[v] + 1q.append(c)cnt += 1return max(dist),cntn,m = map(int,input().split())g = [[] for _ in range(n)]for _ in range(m):a,b = map(int,input().split())g[a-1].append(b-1)g[b-1].append(a-1)Q = int(input())for _ in range(Q):v = int(input())-1res,cnt = dfs(g,v)res = 0 if res==0 else (res-1).bit_length()print(cnt,res)