結果

問題 No.812 Change of Class
ユーザー H3PO4H3PO4
提出日時 2021-02-11 09:58:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 890 ms / 4,000 ms
コード長 652 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 86,704 KB
実行使用メモリ 112,508 KB
最終ジャッジ日時 2023-09-24 23:00:48
合計ジャッジ時間 26,356 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 320 ms
95,432 KB
testcase_01 AC 172 ms
80,012 KB
testcase_02 AC 244 ms
87,072 KB
testcase_03 AC 356 ms
100,284 KB
testcase_04 AC 317 ms
96,964 KB
testcase_05 AC 890 ms
99,356 KB
testcase_06 AC 826 ms
95,000 KB
testcase_07 AC 109 ms
85,852 KB
testcase_08 AC 103 ms
76,532 KB
testcase_09 AC 843 ms
102,788 KB
testcase_10 AC 829 ms
100,484 KB
testcase_11 AC 169 ms
106,624 KB
testcase_12 AC 533 ms
99,716 KB
testcase_13 AC 95 ms
71,840 KB
testcase_14 AC 96 ms
71,308 KB
testcase_15 AC 606 ms
92,912 KB
testcase_16 AC 167 ms
79,020 KB
testcase_17 AC 550 ms
93,072 KB
testcase_18 AC 449 ms
88,756 KB
testcase_19 AC 525 ms
91,644 KB
testcase_20 AC 840 ms
100,592 KB
testcase_21 AC 387 ms
88,996 KB
testcase_22 AC 246 ms
84,136 KB
testcase_23 AC 159 ms
78,972 KB
testcase_24 AC 170 ms
79,424 KB
testcase_25 AC 218 ms
83,304 KB
testcase_26 AC 647 ms
96,588 KB
testcase_27 AC 647 ms
93,580 KB
testcase_28 AC 469 ms
91,852 KB
testcase_29 AC 203 ms
80,004 KB
testcase_30 AC 534 ms
92,312 KB
testcase_31 AC 464 ms
89,708 KB
testcase_32 AC 260 ms
85,464 KB
testcase_33 AC 575 ms
94,976 KB
testcase_34 AC 165 ms
79,212 KB
testcase_35 AC 207 ms
83,916 KB
testcase_36 AC 168 ms
79,552 KB
testcase_37 AC 313 ms
85,196 KB
testcase_38 AC 142 ms
89,072 KB
testcase_39 AC 313 ms
85,268 KB
testcase_40 AC 192 ms
79,892 KB
testcase_41 AC 138 ms
87,556 KB
testcase_42 AC 634 ms
93,944 KB
testcase_43 AC 218 ms
97,340 KB
testcase_44 AC 426 ms
88,612 KB
testcase_45 AC 168 ms
79,384 KB
testcase_46 AC 211 ms
97,040 KB
testcase_47 AC 410 ms
89,228 KB
testcase_48 AC 439 ms
90,648 KB
testcase_49 AC 210 ms
80,136 KB
testcase_50 AC 132 ms
77,320 KB
testcase_51 AC 219 ms
86,252 KB
testcase_52 AC 306 ms
92,388 KB
testcase_53 AC 192 ms
79,844 KB
testcase_54 AC 185 ms
79,652 KB
testcase_55 AC 282 ms
98,064 KB
testcase_56 AC 308 ms
102,800 KB
testcase_57 AC 314 ms
104,992 KB
testcase_58 AC 226 ms
89,132 KB
testcase_59 AC 353 ms
112,508 KB
testcase_60 AC 95 ms
71,784 KB
testcase_61 AC 95 ms
71,752 KB
testcase_62 AC 94 ms
71,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    p, q = (int(x) - 1 for x in input().split())
    G[p].append(q)
    G[q].append(p)


def solve(a):
    dist = [-1] * N
    dist[a] = 0
    # bfs
    d = deque([a])
    num = 0
    while d:
        v = d.popleft()
        dx = dist[v] + 1
        for x in G[v]:
            if dist[x] == -1:
                num += 1
                dist[x] = dx
                d.append(x)
    m = max(dist)
    day = (m - 1).bit_length() if m else 0
    return num, day


Q = int(input())
for _ in range(Q):
    a = int(input()) - 1
    print(*solve(a))
0