結果

問題 No.812 Change of Class
ユーザー stngstng
提出日時 2022-07-06 17:48:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 894 ms / 4,000 ms
コード長 904 bytes
コンパイル時間 914 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 153,252 KB
最終ジャッジ日時 2023-08-24 14:57:33
合計ジャッジ時間 26,017 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 333 ms
96,624 KB
testcase_01 AC 173 ms
79,408 KB
testcase_02 AC 248 ms
87,012 KB
testcase_03 AC 365 ms
101,604 KB
testcase_04 AC 338 ms
98,048 KB
testcase_05 AC 894 ms
109,800 KB
testcase_06 AC 715 ms
103,144 KB
testcase_07 AC 106 ms
85,080 KB
testcase_08 AC 98 ms
76,376 KB
testcase_09 AC 849 ms
109,568 KB
testcase_10 AC 806 ms
109,456 KB
testcase_11 AC 160 ms
106,808 KB
testcase_12 AC 501 ms
102,296 KB
testcase_13 AC 92 ms
71,320 KB
testcase_14 AC 95 ms
71,216 KB
testcase_15 AC 582 ms
96,368 KB
testcase_16 AC 159 ms
78,972 KB
testcase_17 AC 518 ms
97,156 KB
testcase_18 AC 430 ms
89,632 KB
testcase_19 AC 475 ms
94,108 KB
testcase_20 AC 841 ms
109,076 KB
testcase_21 AC 386 ms
89,732 KB
testcase_22 AC 270 ms
84,316 KB
testcase_23 AC 170 ms
78,708 KB
testcase_24 AC 171 ms
78,904 KB
testcase_25 AC 232 ms
82,824 KB
testcase_26 AC 694 ms
102,184 KB
testcase_27 AC 637 ms
98,400 KB
testcase_28 AC 444 ms
92,828 KB
testcase_29 AC 199 ms
79,576 KB
testcase_30 AC 533 ms
96,268 KB
testcase_31 AC 443 ms
92,760 KB
testcase_32 AC 295 ms
84,968 KB
testcase_33 AC 622 ms
100,464 KB
testcase_34 AC 178 ms
78,832 KB
testcase_35 AC 225 ms
83,592 KB
testcase_36 AC 177 ms
78,996 KB
testcase_37 AC 345 ms
85,240 KB
testcase_38 AC 136 ms
88,632 KB
testcase_39 AC 354 ms
85,124 KB
testcase_40 AC 192 ms
79,596 KB
testcase_41 AC 131 ms
87,096 KB
testcase_42 AC 573 ms
95,232 KB
testcase_43 AC 215 ms
92,908 KB
testcase_44 AC 419 ms
89,020 KB
testcase_45 AC 179 ms
79,228 KB
testcase_46 AC 198 ms
95,708 KB
testcase_47 AC 424 ms
89,040 KB
testcase_48 AC 451 ms
91,636 KB
testcase_49 AC 225 ms
80,232 KB
testcase_50 AC 130 ms
77,100 KB
testcase_51 AC 224 ms
84,572 KB
testcase_52 AC 295 ms
90,980 KB
testcase_53 AC 203 ms
79,616 KB
testcase_54 AC 197 ms
79,212 KB
testcase_55 AC 344 ms
122,224 KB
testcase_56 AC 388 ms
137,220 KB
testcase_57 AC 405 ms
143,204 KB
testcase_58 AC 258 ms
97,860 KB
testcase_59 AC 448 ms
153,252 KB
testcase_60 AC 93 ms
71,304 KB
testcase_61 AC 93 ms
71,368 KB
testcase_62 AC 94 ms
71,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import bisect
n,m = map(int,input().split())
pq = [[] for i in range(n)]
for i in range(m):
    p,q = map(int,input().split())
    p -= 1
    q -= 1
    pq[p].append(q)
    pq[q].append(p)

q = int(input())
a = [int(input())-1 for i in range(q)]

ans = []
rui = [2**i for i in range(20)]
#idx = bisect.bisect_left(cnt,8)
#print(cnt)
#print(idx)

for i in range(q):
    chk = [0]*n
    chk[a[i]] = 1
    d = deque()
    d.append([a[i],0])
    mcnt = 0
    while len(d) > 0:
        tmp,cnt = d.popleft()
        for j in pq[tmp]:
            if chk[j] == 0:
                chk[j] = 1
                d.append([j,cnt+1])
                mcnt = cnt+1
    if mcnt == 0:
        ans.append([0,0])
    else:
        idx = bisect.bisect_left(rui,mcnt)
        #ans.append([sum(chk)-1,(mcnt+1)//2])
        ans.append([sum(chk)-1,idx])

for i in range(len(ans)):
    print(*ans[i])
0