結果

問題 No.812 Change of Class
ユーザー ttrttr
提出日時 2020-06-21 18:31:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,721 ms / 4,000 ms
コード長 937 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 238,740 KB
最終ジャッジ日時 2023-09-16 18:40:50
合計ジャッジ時間 72,757 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 399 ms
113,004 KB
testcase_01 AC 198 ms
80,412 KB
testcase_02 AC 295 ms
93,160 KB
testcase_03 AC 464 ms
119,892 KB
testcase_04 AC 385 ms
110,572 KB
testcase_05 AC 3,639 ms
197,292 KB
testcase_06 AC 3,721 ms
201,932 KB
testcase_07 AC 96 ms
94,132 KB
testcase_08 AC 80 ms
75,796 KB
testcase_09 AC 3,072 ms
176,932 KB
testcase_10 AC 3,248 ms
176,964 KB
testcase_11 AC 167 ms
128,756 KB
testcase_12 AC 1,700 ms
135,492 KB
testcase_13 AC 74 ms
71,116 KB
testcase_14 AC 73 ms
71,316 KB
testcase_15 AC 2,257 ms
147,540 KB
testcase_16 AC 348 ms
82,276 KB
testcase_17 AC 2,147 ms
144,188 KB
testcase_18 AC 1,713 ms
127,968 KB
testcase_19 AC 1,797 ms
133,156 KB
testcase_20 AC 3,127 ms
181,768 KB
testcase_21 AC 1,503 ms
122,420 KB
testcase_22 AC 870 ms
99,176 KB
testcase_23 AC 414 ms
83,324 KB
testcase_24 AC 382 ms
83,388 KB
testcase_25 AC 753 ms
94,412 KB
testcase_26 AC 3,043 ms
166,568 KB
testcase_27 AC 2,233 ms
149,668 KB
testcase_28 AC 1,718 ms
132,444 KB
testcase_29 AC 628 ms
89,392 KB
testcase_30 AC 2,421 ms
146,876 KB
testcase_31 AC 1,964 ms
134,208 KB
testcase_32 AC 828 ms
101,048 KB
testcase_33 AC 2,289 ms
151,620 KB
testcase_34 AC 354 ms
81,964 KB
testcase_35 AC 496 ms
88,636 KB
testcase_36 AC 380 ms
83,112 KB
testcase_37 AC 1,083 ms
100,644 KB
testcase_38 AC 135 ms
100,812 KB
testcase_39 AC 940 ms
100,476 KB
testcase_40 AC 348 ms
84,108 KB
testcase_41 AC 126 ms
97,964 KB
testcase_42 AC 1,884 ms
121,748 KB
testcase_43 AC 335 ms
98,828 KB
testcase_44 AC 1,390 ms
108,820 KB
testcase_45 AC 391 ms
83,384 KB
testcase_46 AC 336 ms
103,780 KB
testcase_47 AC 1,461 ms
108,572 KB
testcase_48 AC 1,315 ms
114,196 KB
testcase_49 AC 617 ms
89,228 KB
testcase_50 AC 203 ms
79,136 KB
testcase_51 AC 478 ms
92,404 KB
testcase_52 AC 640 ms
105,996 KB
testcase_53 AC 469 ms
86,148 KB
testcase_54 AC 432 ms
85,228 KB
testcase_55 AC 1,272 ms
185,016 KB
testcase_56 AC 1,496 ms
210,084 KB
testcase_57 AC 1,538 ms
217,832 KB
testcase_58 AC 833 ms
145,140 KB
testcase_59 AC 1,740 ms
238,740 KB
testcase_60 AC 73 ms
71,248 KB
testcase_61 AC 73 ms
71,464 KB
testcase_62 AC 73 ms
71,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
def dijkstra(s):
    inf = 10**9
    d = [inf]*(N+1)
    used = [0]*(N+1)
    h = [(0, s)]
    while h:
        temp = heapq.heappop(h)
        dist = temp[0]
        u = temp[1]
        if used[u] == 1:
            continue
        used[u] = 1
        d[u] = dist
        for v in E[u]:
            if used[v] == 1:
                continue
            heapq.heappush(h, (dist+1, v))
    return d


N,M = map(int, input().split())
E = [[] for _ in range(N+1)]
for _ in range(M):
    p,q = map(int, input().split())
    E[p].append(q)
    E[q].append(p)

Q = int(input())
for _ in range(Q):
    a = int(input())
    d = dijkstra(a)
    num = -1
    dist = 0
    for i in range(1, N+1):
        if d[i] == 10**9:
            continue
        dist = max(dist, d[i]-1)
        num += 1
    cnt = 0
    for i in range(dist+1):
        if cnt >= dist:
            day = i
            break
        cnt += 1<<i
    print(num, day)
0