結果

問題 No.812 Change of Class
ユーザー maspymaspy
提出日時 2020-02-29 21:14:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,179 ms / 4,000 ms
コード長 922 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 85,932 KB
実行使用メモリ 127,436 KB
最終ジャッジ日時 2023-09-03 16:27:03
合計ジャッジ時間 25,160 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 325 ms
106,620 KB
testcase_01 AC 165 ms
80,464 KB
testcase_02 AC 242 ms
91,232 KB
testcase_03 AC 365 ms
115,816 KB
testcase_04 AC 328 ms
109,912 KB
testcase_05 AC 1,179 ms
114,612 KB
testcase_06 AC 667 ms
104,104 KB
testcase_07 AC 111 ms
85,236 KB
testcase_08 AC 105 ms
75,940 KB
testcase_09 AC 908 ms
113,832 KB
testcase_10 AC 887 ms
112,592 KB
testcase_11 AC 160 ms
107,664 KB
testcase_12 AC 574 ms
109,832 KB
testcase_13 AC 97 ms
70,992 KB
testcase_14 AC 95 ms
70,992 KB
testcase_15 AC 680 ms
99,716 KB
testcase_16 AC 156 ms
78,508 KB
testcase_17 AC 626 ms
102,824 KB
testcase_18 AC 461 ms
93,728 KB
testcase_19 AC 669 ms
96,800 KB
testcase_20 AC 886 ms
113,576 KB
testcase_21 AC 418 ms
93,732 KB
testcase_22 AC 248 ms
85,516 KB
testcase_23 AC 165 ms
78,636 KB
testcase_24 AC 157 ms
79,140 KB
testcase_25 AC 218 ms
84,004 KB
testcase_26 AC 768 ms
105,236 KB
testcase_27 AC 758 ms
102,416 KB
testcase_28 AC 504 ms
97,268 KB
testcase_29 AC 195 ms
80,728 KB
testcase_30 AC 527 ms
100,968 KB
testcase_31 AC 455 ms
96,540 KB
testcase_32 AC 274 ms
87,176 KB
testcase_33 AC 670 ms
105,848 KB
testcase_34 AC 158 ms
78,916 KB
testcase_35 AC 212 ms
84,128 KB
testcase_36 AC 161 ms
79,384 KB
testcase_37 AC 312 ms
88,392 KB
testcase_38 AC 124 ms
87,912 KB
testcase_39 AC 327 ms
88,764 KB
testcase_40 AC 176 ms
80,156 KB
testcase_41 AC 121 ms
87,024 KB
testcase_42 AC 663 ms
100,576 KB
testcase_43 AC 196 ms
97,844 KB
testcase_44 AC 433 ms
94,084 KB
testcase_45 AC 160 ms
79,164 KB
testcase_46 AC 196 ms
97,348 KB
testcase_47 AC 368 ms
92,852 KB
testcase_48 AC 458 ms
97,008 KB
testcase_49 AC 214 ms
81,488 KB
testcase_50 AC 120 ms
76,992 KB
testcase_51 AC 224 ms
85,948 KB
testcase_52 AC 310 ms
93,608 KB
testcase_53 AC 180 ms
79,944 KB
testcase_54 AC 177 ms
79,824 KB
testcase_55 AC 281 ms
106,176 KB
testcase_56 AC 311 ms
112,228 KB
testcase_57 AC 326 ms
116,292 KB
testcase_58 AC 226 ms
94,212 KB
testcase_59 AC 355 ms
127,436 KB
testcase_60 AC 94 ms
71,152 KB
testcase_61 AC 91 ms
71,228 KB
testcase_62 AC 93 ms
71,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque

# %%
N, M = map(int, readline().split())
PQ = [tuple(map(int, readline().split())) for _ in range(M)]
Q = int(readline())
A = tuple(map(int, read().split()))


# %%
G = [[] for _ in range(N + 1)]
for p, q in PQ:
    G[p].append(q)
    G[q].append(p)


# %%
def bfs(root):
    dist = [-1] * (N + 1)
    q = deque()
    q.append(root)
    dist[root] = 0
    while q:
        v = q.popleft()
        dw = dist[v] + 1
        for w in G[v]:
            if dist[w] == -1:
                dist[w] = dw
                q.append(w)
    return dist


# %%
for a in A:
    dist = bfs(a)
    max_d = max(dist)
    if max_d == 0:
        print(0, 0)
        continue
    n = (max_d - 1).bit_length()
    friend = sum(x > 0 for x in dist)
    print(friend, n)
0