結果

問題 No.812 Change of Class
ユーザー terasaterasa
提出日時 2022-06-02 20:39:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 934 ms / 4,000 ms
コード長 1,378 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 81,164 KB
実行使用メモリ 105,236 KB
最終ジャッジ日時 2023-10-21 01:19:37
合計ジャッジ時間 21,754 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 249 ms
93,228 KB
testcase_01 AC 106 ms
78,228 KB
testcase_02 AC 173 ms
86,440 KB
testcase_03 AC 281 ms
96,760 KB
testcase_04 AC 254 ms
93,208 KB
testcase_05 AC 934 ms
95,076 KB
testcase_06 AC 775 ms
91,236 KB
testcase_07 AC 55 ms
70,144 KB
testcase_08 AC 49 ms
62,984 KB
testcase_09 AC 911 ms
98,864 KB
testcase_10 AC 848 ms
98,696 KB
testcase_11 AC 98 ms
105,236 KB
testcase_12 AC 451 ms
98,384 KB
testcase_13 AC 45 ms
55,532 KB
testcase_14 AC 44 ms
55,532 KB
testcase_15 AC 592 ms
91,872 KB
testcase_16 AC 97 ms
77,072 KB
testcase_17 AC 513 ms
92,360 KB
testcase_18 AC 319 ms
90,148 KB
testcase_19 AC 411 ms
91,248 KB
testcase_20 AC 879 ms
98,224 KB
testcase_21 AC 345 ms
88,656 KB
testcase_22 AC 185 ms
82,432 KB
testcase_23 AC 96 ms
76,988 KB
testcase_24 AC 103 ms
77,360 KB
testcase_25 AC 161 ms
82,152 KB
testcase_26 AC 699 ms
94,992 KB
testcase_27 AC 577 ms
92,872 KB
testcase_28 AC 379 ms
90,060 KB
testcase_29 AC 132 ms
77,916 KB
testcase_30 AC 550 ms
90,988 KB
testcase_31 AC 426 ms
89,684 KB
testcase_32 AC 198 ms
83,392 KB
testcase_33 AC 506 ms
94,704 KB
testcase_34 AC 100 ms
77,264 KB
testcase_35 AC 151 ms
82,584 KB
testcase_36 AC 108 ms
77,384 KB
testcase_37 AC 267 ms
85,020 KB
testcase_38 AC 67 ms
79,480 KB
testcase_39 AC 257 ms
85,932 KB
testcase_40 AC 127 ms
78,024 KB
testcase_41 AC 63 ms
76,048 KB
testcase_42 AC 481 ms
91,104 KB
testcase_43 AC 132 ms
94,560 KB
testcase_44 AC 348 ms
86,764 KB
testcase_45 AC 109 ms
77,628 KB
testcase_46 AC 142 ms
94,532 KB
testcase_47 AC 374 ms
86,724 KB
testcase_48 AC 423 ms
90,092 KB
testcase_49 AC 152 ms
78,768 KB
testcase_50 AC 68 ms
70,556 KB
testcase_51 AC 154 ms
85,096 KB
testcase_52 AC 242 ms
95,892 KB
testcase_53 AC 129 ms
77,900 KB
testcase_54 AC 122 ms
77,920 KB
testcase_55 AC 220 ms
93,980 KB
testcase_56 AC 248 ms
97,628 KB
testcase_57 AC 257 ms
96,356 KB
testcase_58 AC 171 ms
88,096 KB
testcase_59 AC 292 ms
103,496 KB
testcase_60 AC 45 ms
55,532 KB
testcase_61 AC 45 ms
55,844 KB
testcase_62 AC 45 ms
55,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


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

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

    INF = 1 << 30
    C = [INF] * N
    C[s] = 0
    dq = deque([s])
    cnt = 0
    depth = 0
    while len(dq) > 0:
        v = dq.popleft()
        cnt += 1
        depth = max(depth, C[v])
        for d in E[v]:
            if C[d] > C[v] + 1:
                C[d] = C[v] + 1
                dq.append(d)
    print(cnt - 1, math.ceil(math.log2(depth)) if cnt > 2 else 0)
0