結果

問題 No.812 Change of Class
ユーザー Coki628Coki628
提出日時 2020-08-18 18:57:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,875 ms / 4,000 ms
コード長 1,484 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 126,464 KB
最終ジャッジ日時 2024-04-20 07:50:36
合計ジャッジ時間 39,179 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 561 ms
104,704 KB
testcase_01 AC 174 ms
79,744 KB
testcase_02 AC 360 ms
90,752 KB
testcase_03 AC 654 ms
114,304 KB
testcase_04 AC 588 ms
107,568 KB
testcase_05 AC 1,875 ms
110,464 KB
testcase_06 AC 1,562 ms
100,820 KB
testcase_07 AC 80 ms
71,040 KB
testcase_08 AC 63 ms
64,512 KB
testcase_09 AC 1,622 ms
107,392 KB
testcase_10 AC 1,643 ms
108,604 KB
testcase_11 AC 166 ms
105,472 KB
testcase_12 AC 970 ms
101,120 KB
testcase_13 AC 54 ms
54,400 KB
testcase_14 AC 50 ms
54,400 KB
testcase_15 AC 1,186 ms
97,024 KB
testcase_16 AC 167 ms
78,864 KB
testcase_17 AC 1,068 ms
97,920 KB
testcase_18 AC 768 ms
92,012 KB
testcase_19 AC 875 ms
94,080 KB
testcase_20 AC 1,705 ms
109,184 KB
testcase_21 AC 695 ms
91,008 KB
testcase_22 AC 340 ms
83,840 KB
testcase_23 AC 157 ms
78,848 KB
testcase_24 AC 164 ms
78,336 KB
testcase_25 AC 298 ms
82,816 KB
testcase_26 AC 1,436 ms
125,696 KB
testcase_27 AC 1,146 ms
98,744 KB
testcase_28 AC 814 ms
93,568 KB
testcase_29 AC 260 ms
79,872 KB
testcase_30 AC 1,021 ms
97,152 KB
testcase_31 AC 998 ms
93,420 KB
testcase_32 AC 417 ms
85,248 KB
testcase_33 AC 1,176 ms
100,096 KB
testcase_34 AC 150 ms
78,096 KB
testcase_35 AC 308 ms
83,072 KB
testcase_36 AC 177 ms
79,104 KB
testcase_37 AC 613 ms
87,424 KB
testcase_38 AC 108 ms
81,408 KB
testcase_39 AC 593 ms
86,912 KB
testcase_40 AC 218 ms
79,104 KB
testcase_41 AC 97 ms
77,696 KB
testcase_42 AC 1,242 ms
100,608 KB
testcase_43 AC 224 ms
91,880 KB
testcase_44 AC 805 ms
92,160 KB
testcase_45 AC 174 ms
78,336 KB
testcase_46 AC 221 ms
94,976 KB
testcase_47 AC 850 ms
93,568 KB
testcase_48 AC 896 ms
93,824 KB
testcase_49 AC 297 ms
81,100 KB
testcase_50 AC 104 ms
77,184 KB
testcase_51 AC 304 ms
84,864 KB
testcase_52 AC 476 ms
94,592 KB
testcase_53 AC 223 ms
79,744 KB
testcase_54 AC 219 ms
79,360 KB
testcase_55 AC 420 ms
103,936 KB
testcase_56 AC 479 ms
113,152 KB
testcase_57 AC 503 ms
114,492 KB
testcase_58 AC 303 ms
90,496 KB
testcase_59 AC 574 ms
126,464 KB
testcase_60 AC 46 ms
54,332 KB
testcase_61 AC 48 ms
54,400 KB
testcase_62 AC 50 ms
54,400 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 = [INF] * N
    dist[src] = 0
    cnt = 0
    while que:
        u = que.popleft()
        for v in nodes[u]:
            if dist[v] != INF:
                continue
            dist[v] = dist[u] + 1
            que.append(v)
            cnt += 1
    mx = 0
    for i in range(N):
        if dist[i] != INF 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