結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-06 17:16:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 775 bytes |
| コンパイル時間 | 252 ms |
| コンパイル使用メモリ | 82,560 KB |
| 実行使用メモリ | 161,760 KB |
| 最終ジャッジ日時 | 2024-12-22 21:01:34 |
| 合計ジャッジ時間 | 22,779 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 48 |
ソースコード
from collections import deque
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 = []
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])
elif mcnt == 1:
ans.append([sum(chk)-1,0])
else:
ans.append([sum(chk)-1,(mcnt+1)//2])
for i in range(len(ans)):
print(*ans[i])