結果
問題 | No.812 Change of Class |
ユーザー | Coki628 |
提出日時 | 2020-08-18 19:00:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,100 ms / 4,000 ms |
コード長 | 1,481 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 83,040 KB |
実行使用メモリ | 110,760 KB |
最終ジャッジ日時 | 2024-10-12 03:08:25 |
合計ジャッジ時間 | 26,219 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 418 ms
92,812 KB |
testcase_01 | AC | 130 ms
79,076 KB |
testcase_02 | AC | 270 ms
86,076 KB |
testcase_03 | AC | 488 ms
97,324 KB |
testcase_04 | AC | 457 ms
94,088 KB |
testcase_05 | AC | 1,100 ms
96,564 KB |
testcase_06 | AC | 710 ms
92,480 KB |
testcase_07 | AC | 57 ms
70,956 KB |
testcase_08 | AC | 48 ms
64,972 KB |
testcase_09 | AC | 989 ms
98,928 KB |
testcase_10 | AC | 1,076 ms
97,096 KB |
testcase_11 | AC | 106 ms
106,004 KB |
testcase_12 | AC | 629 ms
98,540 KB |
testcase_13 | AC | 42 ms
54,964 KB |
testcase_14 | AC | 42 ms
56,008 KB |
testcase_15 | AC | 734 ms
90,780 KB |
testcase_16 | AC | 127 ms
78,048 KB |
testcase_17 | AC | 641 ms
94,132 KB |
testcase_18 | AC | 522 ms
88,920 KB |
testcase_19 | AC | 563 ms
90,204 KB |
testcase_20 | AC | 1,056 ms
97,604 KB |
testcase_21 | AC | 509 ms
87,428 KB |
testcase_22 | AC | 233 ms
83,680 KB |
testcase_23 | AC | 113 ms
77,712 KB |
testcase_24 | AC | 119 ms
78,224 KB |
testcase_25 | AC | 207 ms
82,376 KB |
testcase_26 | AC | 1,061 ms
94,604 KB |
testcase_27 | AC | 923 ms
92,508 KB |
testcase_28 | AC | 550 ms
90,156 KB |
testcase_29 | AC | 172 ms
79,020 KB |
testcase_30 | AC | 669 ms
90,580 KB |
testcase_31 | AC | 590 ms
89,312 KB |
testcase_32 | AC | 263 ms
84,952 KB |
testcase_33 | AC | 727 ms
93,512 KB |
testcase_34 | AC | 113 ms
78,356 KB |
testcase_35 | AC | 197 ms
83,180 KB |
testcase_36 | AC | 125 ms
77,888 KB |
testcase_37 | AC | 417 ms
84,288 KB |
testcase_38 | AC | 72 ms
80,852 KB |
testcase_39 | AC | 353 ms
84,964 KB |
testcase_40 | AC | 141 ms
78,864 KB |
testcase_41 | AC | 66 ms
77,412 KB |
testcase_42 | AC | 869 ms
90,876 KB |
testcase_43 | AC | 162 ms
91,624 KB |
testcase_44 | AC | 501 ms
87,552 KB |
testcase_45 | AC | 123 ms
77,900 KB |
testcase_46 | AC | 154 ms
95,272 KB |
testcase_47 | AC | 512 ms
87,404 KB |
testcase_48 | AC | 595 ms
89,932 KB |
testcase_49 | AC | 196 ms
79,436 KB |
testcase_50 | AC | 76 ms
74,708 KB |
testcase_51 | AC | 199 ms
84,168 KB |
testcase_52 | AC | 334 ms
91,192 KB |
testcase_53 | AC | 159 ms
78,708 KB |
testcase_54 | AC | 145 ms
78,640 KB |
testcase_55 | AC | 324 ms
94,484 KB |
testcase_56 | AC | 373 ms
98,964 KB |
testcase_57 | AC | 392 ms
102,260 KB |
testcase_58 | AC | 236 ms
87,888 KB |
testcase_59 | AC | 439 ms
110,760 KB |
testcase_60 | AC | 39 ms
55,912 KB |
testcase_61 | AC | 41 ms
55,712 KB |
testcase_62 | AC | 40 ms
56,712 KB |
ソースコード
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)