結果

問題 No.812 Change of Class
ユーザー neterukunneterukun
提出日時 2019-06-14 18:57:55
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,414 ms / 4,000 ms
コード長 897 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 196,504 KB
最終ジャッジ日時 2023-09-03 15:33:33
合計ジャッジ時間 32,437 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 399 ms
109,100 KB
testcase_01 AC 177 ms
80,896 KB
testcase_02 AC 283 ms
91,972 KB
testcase_03 AC 457 ms
117,644 KB
testcase_04 AC 412 ms
110,316 KB
testcase_05 AC 1,414 ms
128,752 KB
testcase_06 AC 1,139 ms
117,316 KB
testcase_07 AC 118 ms
85,048 KB
testcase_08 AC 104 ms
76,076 KB
testcase_09 AC 1,165 ms
125,028 KB
testcase_10 AC 1,258 ms
126,852 KB
testcase_11 AC 187 ms
102,888 KB
testcase_12 AC 739 ms
109,572 KB
testcase_13 AC 95 ms
71,080 KB
testcase_14 AC 96 ms
71,052 KB
testcase_15 AC 920 ms
104,864 KB
testcase_16 AC 179 ms
79,428 KB
testcase_17 AC 834 ms
107,556 KB
testcase_18 AC 609 ms
97,876 KB
testcase_19 AC 774 ms
101,836 KB
testcase_20 AC 1,266 ms
126,520 KB
testcase_21 AC 577 ms
96,020 KB
testcase_22 AC 290 ms
86,548 KB
testcase_23 AC 173 ms
79,256 KB
testcase_24 AC 177 ms
79,488 KB
testcase_25 AC 260 ms
84,280 KB
testcase_26 AC 911 ms
119,196 KB
testcase_27 AC 964 ms
110,384 KB
testcase_28 AC 679 ms
100,536 KB
testcase_29 AC 227 ms
81,400 KB
testcase_30 AC 748 ms
106,920 KB
testcase_31 AC 739 ms
100,828 KB
testcase_32 AC 333 ms
87,116 KB
testcase_33 AC 802 ms
110,932 KB
testcase_34 AC 171 ms
79,240 KB
testcase_35 AC 260 ms
83,456 KB
testcase_36 AC 183 ms
79,188 KB
testcase_37 AC 400 ms
89,076 KB
testcase_38 AC 154 ms
88,252 KB
testcase_39 AC 410 ms
88,596 KB
testcase_40 AC 203 ms
80,536 KB
testcase_41 AC 147 ms
86,880 KB
testcase_42 AC 859 ms
103,760 KB
testcase_43 AC 246 ms
96,344 KB
testcase_44 AC 554 ms
94,516 KB
testcase_45 AC 188 ms
79,408 KB
testcase_46 AC 234 ms
96,436 KB
testcase_47 AC 574 ms
95,284 KB
testcase_48 AC 632 ms
97,828 KB
testcase_49 AC 247 ms
81,804 KB
testcase_50 AC 130 ms
77,004 KB
testcase_51 AC 246 ms
85,340 KB
testcase_52 AC 395 ms
93,512 KB
testcase_53 AC 205 ms
80,548 KB
testcase_54 AC 198 ms
80,184 KB
testcase_55 AC 404 ms
141,548 KB
testcase_56 AC 462 ms
163,108 KB
testcase_57 AC 490 ms
167,208 KB
testcase_58 AC 297 ms
106,040 KB
testcase_59 AC 550 ms
196,504 KB
testcase_60 AC 94 ms
71,012 KB
testcase_61 AC 94 ms
71,304 KB
testcase_62 AC 96 ms
71,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
sys.setrecursionlimit(200000)


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
q = int(input())
a = [int(input()) for i in range(q)]

tree = [[] for i in range(n)]
for i in range(m):
    tree[info[i][0] - 1].append(info[i][1] - 1)
    tree[info[i][1] - 1].append(info[i][0] - 1)

def bfs(a):
    visited = [False]*n
    cnt = 0
    q = deque([])
    q.append([0, a])
    visited[a] = True
    while q:
        times, pos = q.popleft()
        for next_pos in tree[pos]:
            if not visited[next_pos]:
                visited[next_pos] = True
                cnt += 1
                q.append([times + 1, next_pos])
    if times == 0 or times == 1:
        day = 0
    else:
        day = (times-1).bit_length()
    return cnt, day


for i in range(q):
    ans1, ans2 = bfs(a[i] - 1)
    print(ans1, ans2)
0