結果

問題 No.812 Change of Class
ユーザー Coki628Coki628
提出日時 2020-08-18 19:00:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 817 ms / 4,000 ms
コード長 1,481 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 82,536 KB
実行使用メモリ 110,976 KB
最終ジャッジ日時 2024-04-20 07:51:24
合計ジャッジ時間 21,036 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 371 ms
93,208 KB
testcase_01 AC 119 ms
78,848 KB
testcase_02 AC 240 ms
86,132 KB
testcase_03 AC 424 ms
97,408 KB
testcase_04 AC 390 ms
93,984 KB
testcase_05 AC 817 ms
96,768 KB
testcase_06 AC 537 ms
92,744 KB
testcase_07 AC 66 ms
70,272 KB
testcase_08 AC 42 ms
63,872 KB
testcase_09 AC 693 ms
99,060 KB
testcase_10 AC 714 ms
97,440 KB
testcase_11 AC 92 ms
105,388 KB
testcase_12 AC 518 ms
98,400 KB
testcase_13 AC 38 ms
54,620 KB
testcase_14 AC 37 ms
54,528 KB
testcase_15 AC 530 ms
90,076 KB
testcase_16 AC 113 ms
77,952 KB
testcase_17 AC 510 ms
93,824 KB
testcase_18 AC 400 ms
89,136 KB
testcase_19 AC 433 ms
89,908 KB
testcase_20 AC 758 ms
97,536 KB
testcase_21 AC 361 ms
87,684 KB
testcase_22 AC 194 ms
83,712 KB
testcase_23 AC 99 ms
77,696 KB
testcase_24 AC 107 ms
78,248 KB
testcase_25 AC 177 ms
82,304 KB
testcase_26 AC 680 ms
94,588 KB
testcase_27 AC 654 ms
92,808 KB
testcase_28 AC 413 ms
90,240 KB
testcase_29 AC 157 ms
78,976 KB
testcase_30 AC 530 ms
90,496 KB
testcase_31 AC 451 ms
89,628 KB
testcase_32 AC 222 ms
84,864 KB
testcase_33 AC 600 ms
93,472 KB
testcase_34 AC 105 ms
78,208 KB
testcase_35 AC 171 ms
83,496 KB
testcase_36 AC 111 ms
77,824 KB
testcase_37 AC 339 ms
84,096 KB
testcase_38 AC 65 ms
80,256 KB
testcase_39 AC 292 ms
84,480 KB
testcase_40 AC 123 ms
78,848 KB
testcase_41 AC 59 ms
77,312 KB
testcase_42 AC 612 ms
90,624 KB
testcase_43 AC 135 ms
91,392 KB
testcase_44 AC 387 ms
87,256 KB
testcase_45 AC 112 ms
77,952 KB
testcase_46 AC 129 ms
95,116 KB
testcase_47 AC 397 ms
87,744 KB
testcase_48 AC 457 ms
90,112 KB
testcase_49 AC 167 ms
79,488 KB
testcase_50 AC 68 ms
74,368 KB
testcase_51 AC 171 ms
84,292 KB
testcase_52 AC 251 ms
91,360 KB
testcase_53 AC 139 ms
78,732 KB
testcase_54 AC 130 ms
78,232 KB
testcase_55 AC 287 ms
94,464 KB
testcase_56 AC 327 ms
99,028 KB
testcase_57 AC 337 ms
102,408 KB
testcase_58 AC 207 ms
87,252 KB
testcase_59 AC 398 ms
110,976 KB
testcase_60 AC 40 ms
54,432 KB
testcase_61 AC 37 ms
54,784 KB
testcase_62 AC 38 ms
54,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import log2

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

def bfs(nodes, src):
    """ BFS(一般グラフ、重みなし) """
    from collections import deque

    N = len(nodes)
    que = deque([src])
    dist = [-1] * N
    dist[src] = 0
    cnt = 0
    while que:
        u = que.popleft()
        for v in nodes[u]:
            if dist[v] != -1:
                continue
            dist[v] = dist[u] + 1
            que.append(v)
            cnt += 1
    mx = 0
    for i in range(N):
        if dist[i] != -1 and dist[i] >= 2:
            mx = max(mx, ceil(log2(dist[i])))
    return cnt, mx

N, M = MAP()
nodes = [[] for i in range(N)]
for i in range(M):
    a, b = MAP()
    a -= 1; b -= 1
    nodes[a].append(b)
    nodes[b].append(a)

Q = INT()
for _ in range(Q):
    x = INT()
    x -= 1

    cnt, mx = bfs(nodes, x)
    print(cnt, mx)
0