結果

問題 No.812 Change of Class
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-26 02:34:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 926 ms / 4,000 ms
コード長 796 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 81,704 KB
実行使用メモリ 102,164 KB
最終ジャッジ日時 2023-10-24 04:23:01
合計ジャッジ時間 22,473 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 225 ms
92,476 KB
testcase_01 AC 95 ms
77,532 KB
testcase_02 AC 155 ms
85,568 KB
testcase_03 AC 256 ms
94,844 KB
testcase_04 AC 232 ms
92,784 KB
testcase_05 AC 926 ms
94,852 KB
testcase_06 AC 812 ms
90,464 KB
testcase_07 AC 52 ms
70,172 KB
testcase_08 AC 46 ms
63,008 KB
testcase_09 AC 872 ms
98,328 KB
testcase_10 AC 742 ms
99,560 KB
testcase_11 AC 78 ms
96,488 KB
testcase_12 AC 519 ms
99,800 KB
testcase_13 AC 41 ms
55,468 KB
testcase_14 AC 41 ms
55,468 KB
testcase_15 AC 536 ms
91,736 KB
testcase_16 AC 88 ms
76,528 KB
testcase_17 AC 450 ms
91,892 KB
testcase_18 AC 317 ms
89,180 KB
testcase_19 AC 410 ms
90,568 KB
testcase_20 AC 873 ms
97,828 KB
testcase_21 AC 356 ms
87,204 KB
testcase_22 AC 180 ms
83,664 KB
testcase_23 AC 91 ms
76,468 KB
testcase_24 AC 93 ms
76,744 KB
testcase_25 AC 147 ms
82,132 KB
testcase_26 AC 642 ms
94,860 KB
testcase_27 AC 587 ms
91,920 KB
testcase_28 AC 448 ms
89,516 KB
testcase_29 AC 120 ms
77,488 KB
testcase_30 AC 511 ms
91,656 KB
testcase_31 AC 423 ms
89,432 KB
testcase_32 AC 202 ms
83,804 KB
testcase_33 AC 459 ms
93,852 KB
testcase_34 AC 93 ms
76,696 KB
testcase_35 AC 136 ms
82,428 KB
testcase_36 AC 98 ms
77,216 KB
testcase_37 AC 252 ms
84,248 KB
testcase_38 AC 62 ms
77,032 KB
testcase_39 AC 245 ms
85,336 KB
testcase_40 AC 118 ms
77,452 KB
testcase_41 AC 59 ms
73,596 KB
testcase_42 AC 454 ms
90,496 KB
testcase_43 AC 136 ms
95,208 KB
testcase_44 AC 350 ms
86,648 KB
testcase_45 AC 95 ms
76,832 KB
testcase_46 AC 125 ms
94,604 KB
testcase_47 AC 355 ms
86,792 KB
testcase_48 AC 338 ms
90,104 KB
testcase_49 AC 135 ms
78,340 KB
testcase_50 AC 59 ms
68,184 KB
testcase_51 AC 137 ms
84,604 KB
testcase_52 AC 209 ms
89,756 KB
testcase_53 AC 115 ms
77,204 KB
testcase_54 AC 110 ms
77,280 KB
testcase_55 AC 199 ms
93,012 KB
testcase_56 AC 224 ms
98,184 KB
testcase_57 AC 228 ms
96,940 KB
testcase_58 AC 151 ms
86,736 KB
testcase_59 AC 253 ms
102,164 KB
testcase_60 AC 41 ms
55,468 KB
testcase_61 AC 42 ms
55,468 KB
testcase_62 AC 42 ms
55,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

Q = int(input())
for _ in range(Q):
    a = int(input()) - 1

    dist = [-1] * N
    dist[a] = 0

    size = 0
    que = deque([a])
    while que:
        s = que.popleft()
        size += 1
        d = dist[s]
        for t in edge[s]:
            if dist[t] == -1:
                dist[t] = d + 1
                que.append(t)

    if d <= 1:
        print(size - 1, 0)
    else:
        d -= 1
        time = 0
        while d:
            time += 1
            d //= 2
        print(size - 1, time)
0