結果
問題 |
No.812 Change of Class
|
ユーザー |
![]() |
提出日時 | 2019-06-14 18:38:17 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 896 bytes |
コンパイル時間 | 379 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 104,584 KB |
最終ジャッジ日時 | 2024-06-12 21:11:32 |
合計ジャッジ時間 | 12,060 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 RE * 2 |
other | RE * 60 |
ソースコード
from collections import deque import sys sys.setrecursionlimit(2000) n, m = map(int, input().split()) info = [list(map(int, input().split())) for i in range(m)] q = int(input()) a = [int(input()) for i in range(q)] tree = [[] for i in range(n)] for i in range(m): tree[info[i][0] - 1].append(info[i][1] - 1) tree[info[i][1] - 1].append(info[i][0] - 1) def bfs(a): visited = [False]*n cnt = 0 q = deque([]) q.append([0, a]) visited[a] = True while q: times, pos = q.popleft() for next_pos in tree[pos]: if not visited[next_pos]: visited[next_pos] = True cnt += 1 q.append([times + 1, next_pos]) if times == 1: times = 0 else: times = -(-(times) // å2) cnt = cnt return times, cnt for i in range(q): ans1, ans2 = bfs(a[i] - 1) print(ans2, ans1)