結果

問題 No.812 Change of Class
ユーザー stngstng
提出日時 2022-07-06 17:16:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 86,464 KB
実行使用メモリ 151,172 KB
最終ジャッジ日時 2023-08-24 13:41:59
合計ジャッジ時間 28,669 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 102 ms
85,136 KB
testcase_08 AC 97 ms
76,344 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 157 ms
106,704 KB
testcase_12 WA -
testcase_13 AC 90 ms
71,392 KB
testcase_14 AC 90 ms
71,404 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 128 ms
88,812 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 127 ms
87,324 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 339 ms
122,824 KB
testcase_56 AC 383 ms
136,552 KB
testcase_57 AC 399 ms
141,068 KB
testcase_58 AC 258 ms
100,532 KB
testcase_59 AC 438 ms
151,172 KB
testcase_60 AC 91 ms
71,156 KB
testcase_61 AC 92 ms
71,324 KB
testcase_62 AC 92 ms
71,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0