結果

問題 No.812 Change of Class
ユーザー kohei2019kohei2019
提出日時 2022-04-18 23:15:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 823 ms / 4,000 ms
コード長 979 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 154,268 KB
最終ジャッジ日時 2023-08-28 20:12:30
合計ジャッジ時間 27,561 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 398 ms
106,728 KB
testcase_01 AC 177 ms
80,364 KB
testcase_02 AC 279 ms
97,176 KB
testcase_03 AC 443 ms
111,672 KB
testcase_04 AC 407 ms
108,348 KB
testcase_05 AC 819 ms
110,472 KB
testcase_06 AC 740 ms
102,856 KB
testcase_07 AC 133 ms
103,988 KB
testcase_08 AC 102 ms
77,276 KB
testcase_09 AC 806 ms
121,036 KB
testcase_10 AC 796 ms
119,780 KB
testcase_11 AC 225 ms
154,268 KB
testcase_12 AC 545 ms
125,636 KB
testcase_13 AC 89 ms
71,368 KB
testcase_14 AC 87 ms
71,776 KB
testcase_15 AC 626 ms
108,176 KB
testcase_16 AC 170 ms
79,276 KB
testcase_17 AC 548 ms
110,740 KB
testcase_18 AC 448 ms
104,996 KB
testcase_19 AC 516 ms
112,408 KB
testcase_20 AC 823 ms
116,484 KB
testcase_21 AC 435 ms
103,068 KB
testcase_22 AC 281 ms
97,304 KB
testcase_23 AC 161 ms
79,132 KB
testcase_24 AC 182 ms
79,784 KB
testcase_25 AC 247 ms
89,440 KB
testcase_26 AC 690 ms
110,712 KB
testcase_27 AC 637 ms
111,012 KB
testcase_28 AC 564 ms
107,716 KB
testcase_29 AC 214 ms
80,232 KB
testcase_30 AC 533 ms
106,424 KB
testcase_31 AC 522 ms
103,708 KB
testcase_32 AC 309 ms
96,636 KB
testcase_33 AC 569 ms
113,420 KB
testcase_34 AC 180 ms
79,472 KB
testcase_35 AC 227 ms
87,840 KB
testcase_36 AC 171 ms
79,608 KB
testcase_37 AC 356 ms
95,736 KB
testcase_38 AC 163 ms
110,276 KB
testcase_39 AC 349 ms
96,332 KB
testcase_40 AC 200 ms
80,204 KB
testcase_41 AC 157 ms
106,252 KB
testcase_42 AC 608 ms
103,592 KB
testcase_43 AC 242 ms
119,252 KB
testcase_44 AC 460 ms
99,032 KB
testcase_45 AC 168 ms
79,244 KB
testcase_46 AC 240 ms
121,120 KB
testcase_47 AC 452 ms
97,548 KB
testcase_48 AC 460 ms
106,264 KB
testcase_49 AC 217 ms
80,912 KB
testcase_50 AC 120 ms
77,360 KB
testcase_51 AC 227 ms
91,412 KB
testcase_52 AC 325 ms
107,668 KB
testcase_53 AC 195 ms
80,292 KB
testcase_54 AC 191 ms
80,280 KB
testcase_55 AC 346 ms
107,124 KB
testcase_56 AC 382 ms
111,084 KB
testcase_57 AC 400 ms
116,160 KB
testcase_58 AC 269 ms
97,564 KB
testcase_59 AC 440 ms
119,852 KB
testcase_60 AC 94 ms
71,712 KB
testcase_61 AC 91 ms
71,560 KB
testcase_62 AC 88 ms
71,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N,M = map(int,input().split())
lsg = [[] for i in range(N)]
for i in range(M):
    p,q = map(int,input().split())
    p -= 1
    q -= 1
    lsg[p].append(q)
    lsg[q].append(p)
Q = int(input())
ans = []
inf = float('INF')
for i in range(Q):
    a = int(input())-1
    used = [False]*(N)
    d = collections.deque([a])
    cost = [inf]*(N)
    cost[a] = 0
    while d:
        n = d.popleft()
        if used[n]:
            continue
        used[n] = True
        for j in lsg[n]:
            if used[j]:
                continue
            if cost[j] > cost[n]+1:
                cost[j] = cost[n]+1
                d.append(j)
    cnt = 0
    maxn = 0
    for j in range(N):
        if cost[j] != inf:
            cnt += 1
            maxn = max(maxn,cost[j])
    if maxn == 0:
        ans.append((0,0))
    elif maxn == 1:
        ans.append((cnt-1,0))
    else:
        ans.append((cnt-1,len(bin(maxn-1))-2))
for i in range(Q):
    print(*ans[i],sep=' ')
0