結果

問題 No.812 Change of Class
ユーザー 👑 rin204rin204
提出日時 2022-07-10 16:20:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,138 ms / 4,000 ms
コード長 689 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 107,508 KB
最終ジャッジ日時 2023-09-01 23:13:48
合計ジャッジ時間 29,205 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 316 ms
94,940 KB
testcase_01 AC 165 ms
80,012 KB
testcase_02 AC 238 ms
88,508 KB
testcase_03 AC 353 ms
98,120 KB
testcase_04 AC 327 ms
95,116 KB
testcase_05 AC 1,138 ms
98,000 KB
testcase_06 AC 700 ms
93,520 KB
testcase_07 AC 108 ms
85,824 KB
testcase_08 AC 100 ms
76,812 KB
testcase_09 AC 820 ms
102,600 KB
testcase_10 AC 976 ms
101,808 KB
testcase_11 AC 166 ms
107,508 KB
testcase_12 AC 643 ms
100,292 KB
testcase_13 AC 91 ms
71,628 KB
testcase_14 AC 89 ms
71,800 KB
testcase_15 AC 637 ms
94,172 KB
testcase_16 AC 171 ms
79,332 KB
testcase_17 AC 722 ms
94,940 KB
testcase_18 AC 493 ms
90,948 KB
testcase_19 AC 498 ms
92,680 KB
testcase_20 AC 1,019 ms
100,256 KB
testcase_21 AC 488 ms
90,612 KB
testcase_22 AC 257 ms
86,464 KB
testcase_23 AC 166 ms
79,252 KB
testcase_24 AC 173 ms
79,516 KB
testcase_25 AC 234 ms
82,900 KB
testcase_26 AC 991 ms
97,344 KB
testcase_27 AC 904 ms
94,804 KB
testcase_28 AC 637 ms
93,276 KB
testcase_29 AC 212 ms
80,380 KB
testcase_30 AC 679 ms
93,516 KB
testcase_31 AC 604 ms
92,940 KB
testcase_32 AC 275 ms
87,516 KB
testcase_33 AC 804 ms
97,384 KB
testcase_34 AC 163 ms
79,236 KB
testcase_35 AC 228 ms
83,148 KB
testcase_36 AC 172 ms
79,568 KB
testcase_37 AC 346 ms
88,040 KB
testcase_38 AC 133 ms
88,912 KB
testcase_39 AC 370 ms
87,472 KB
testcase_40 AC 190 ms
80,096 KB
testcase_41 AC 134 ms
87,964 KB
testcase_42 AC 716 ms
94,044 KB
testcase_43 AC 216 ms
93,568 KB
testcase_44 AC 480 ms
89,668 KB
testcase_45 AC 169 ms
79,528 KB
testcase_46 AC 195 ms
93,908 KB
testcase_47 AC 448 ms
90,636 KB
testcase_48 AC 450 ms
93,000 KB
testcase_49 AC 216 ms
80,680 KB
testcase_50 AC 127 ms
77,664 KB
testcase_51 AC 214 ms
84,448 KB
testcase_52 AC 301 ms
94,084 KB
testcase_53 AC 193 ms
80,080 KB
testcase_54 AC 197 ms
79,848 KB
testcase_55 AC 282 ms
95,840 KB
testcase_56 AC 316 ms
100,872 KB
testcase_57 AC 321 ms
101,592 KB
testcase_58 AC 235 ms
89,020 KB
testcase_59 AC 351 ms
105,476 KB
testcase_60 AC 94 ms
71,440 KB
testcase_61 AC 95 ms
71,504 KB
testcase_62 AC 94 ms
71,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append(v)
    edges[v].append(u)

Q = int(input())
for _ in range(Q):
    a = int(input()) - 1
    queue = deque()
    queue.append(a)
    dist = [-1] * n
    dist[a] = 0
    ans = 0
    while queue:
        pos = queue.popleft()
        for npos in edges[pos]:
            if dist[npos] != -1:
                continue
            dist[npos] = dist[pos] + 1
            queue.append(npos)
            ans += 1
    ma = max(dist)
    c = 0
    while (1 << c) < ma:
        c += 1
    print(ans, c)
    
0