結果

問題 No.812 Change of Class
ユーザー maspymaspy
提出日時 2020-03-30 10:55:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,146 ms / 4,000 ms
コード長 906 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 127,868 KB
最終ジャッジ日時 2023-09-03 16:25:53
合計ジャッジ時間 27,257 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 328 ms
107,188 KB
testcase_01 AC 162 ms
81,436 KB
testcase_02 AC 242 ms
91,576 KB
testcase_03 AC 367 ms
116,340 KB
testcase_04 AC 327 ms
110,640 KB
testcase_05 AC 1,146 ms
115,304 KB
testcase_06 AC 642 ms
104,140 KB
testcase_07 AC 105 ms
85,732 KB
testcase_08 AC 99 ms
76,552 KB
testcase_09 AC 876 ms
114,764 KB
testcase_10 AC 838 ms
112,900 KB
testcase_11 AC 153 ms
108,144 KB
testcase_12 AC 571 ms
110,528 KB
testcase_13 AC 89 ms
71,576 KB
testcase_14 AC 89 ms
71,548 KB
testcase_15 AC 678 ms
100,328 KB
testcase_16 AC 151 ms
79,080 KB
testcase_17 AC 666 ms
103,048 KB
testcase_18 AC 451 ms
94,624 KB
testcase_19 AC 512 ms
97,324 KB
testcase_20 AC 971 ms
114,120 KB
testcase_21 AC 487 ms
94,476 KB
testcase_22 AC 257 ms
85,792 KB
testcase_23 AC 164 ms
79,336 KB
testcase_24 AC 155 ms
79,644 KB
testcase_25 AC 221 ms
84,416 KB
testcase_26 AC 862 ms
105,836 KB
testcase_27 AC 809 ms
102,976 KB
testcase_28 AC 585 ms
98,104 KB
testcase_29 AC 198 ms
80,860 KB
testcase_30 AC 641 ms
101,464 KB
testcase_31 AC 545 ms
97,268 KB
testcase_32 AC 311 ms
87,712 KB
testcase_33 AC 791 ms
106,396 KB
testcase_34 AC 158 ms
79,432 KB
testcase_35 AC 226 ms
84,380 KB
testcase_36 AC 166 ms
79,696 KB
testcase_37 AC 330 ms
88,536 KB
testcase_38 AC 123 ms
88,200 KB
testcase_39 AC 351 ms
89,112 KB
testcase_40 AC 179 ms
80,672 KB
testcase_41 AC 118 ms
87,552 KB
testcase_42 AC 819 ms
100,920 KB
testcase_43 AC 211 ms
98,240 KB
testcase_44 AC 526 ms
94,520 KB
testcase_45 AC 165 ms
79,492 KB
testcase_46 AC 210 ms
98,148 KB
testcase_47 AC 435 ms
93,592 KB
testcase_48 AC 613 ms
97,768 KB
testcase_49 AC 223 ms
81,880 KB
testcase_50 AC 117 ms
77,764 KB
testcase_51 AC 240 ms
86,396 KB
testcase_52 AC 390 ms
93,832 KB
testcase_53 AC 182 ms
80,652 KB
testcase_54 AC 179 ms
80,444 KB
testcase_55 AC 288 ms
106,320 KB
testcase_56 AC 319 ms
112,656 KB
testcase_57 AC 327 ms
117,060 KB
testcase_58 AC 232 ms
94,804 KB
testcase_59 AC 368 ms
127,868 KB
testcase_60 AC 92 ms
71,512 KB
testcase_61 AC 93 ms
71,256 KB
testcase_62 AC 93 ms
71,272 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(int(readline()) for _ in range(Q))

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