結果

問題 No.812 Change of Class
ユーザー qibqib
提出日時 2023-04-05 01:40:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 719 ms / 4,000 ms
コード長 806 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,788 KB
実行使用メモリ 104,564 KB
最終ジャッジ日時 2024-04-09 03:00:58
合計ジャッジ時間 19,963 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 302 ms
92,944 KB
testcase_01 AC 127 ms
78,900 KB
testcase_02 AC 200 ms
87,484 KB
testcase_03 AC 328 ms
95,392 KB
testcase_04 AC 291 ms
93,748 KB
testcase_05 AC 719 ms
95,212 KB
testcase_06 AC 581 ms
91,720 KB
testcase_07 AC 59 ms
72,924 KB
testcase_08 AC 49 ms
65,744 KB
testcase_09 AC 689 ms
100,676 KB
testcase_10 AC 644 ms
99,188 KB
testcase_11 AC 124 ms
104,564 KB
testcase_12 AC 462 ms
101,736 KB
testcase_13 AC 40 ms
54,044 KB
testcase_14 AC 39 ms
54,700 KB
testcase_15 AC 483 ms
92,972 KB
testcase_16 AC 120 ms
77,560 KB
testcase_17 AC 452 ms
92,968 KB
testcase_18 AC 348 ms
89,784 KB
testcase_19 AC 393 ms
92,332 KB
testcase_20 AC 685 ms
97,792 KB
testcase_21 AC 327 ms
89,372 KB
testcase_22 AC 199 ms
85,172 KB
testcase_23 AC 111 ms
77,568 KB
testcase_24 AC 127 ms
78,040 KB
testcase_25 AC 172 ms
82,920 KB
testcase_26 AC 574 ms
96,420 KB
testcase_27 AC 502 ms
94,052 KB
testcase_28 AC 364 ms
91,044 KB
testcase_29 AC 153 ms
78,596 KB
testcase_30 AC 447 ms
92,280 KB
testcase_31 AC 386 ms
91,220 KB
testcase_32 AC 227 ms
85,408 KB
testcase_33 AC 432 ms
94,920 KB
testcase_34 AC 133 ms
78,372 KB
testcase_35 AC 165 ms
82,932 KB
testcase_36 AC 119 ms
77,808 KB
testcase_37 AC 262 ms
85,752 KB
testcase_38 AC 100 ms
89,804 KB
testcase_39 AC 259 ms
86,596 KB
testcase_40 AC 146 ms
78,744 KB
testcase_41 AC 94 ms
84,952 KB
testcase_42 AC 483 ms
91,760 KB
testcase_43 AC 179 ms
97,300 KB
testcase_44 AC 362 ms
87,940 KB
testcase_45 AC 121 ms
78,212 KB
testcase_46 AC 158 ms
95,804 KB
testcase_47 AC 350 ms
87,248 KB
testcase_48 AC 339 ms
91,184 KB
testcase_49 AC 159 ms
79,360 KB
testcase_50 AC 76 ms
74,036 KB
testcase_51 AC 172 ms
85,440 KB
testcase_52 AC 248 ms
93,408 KB
testcase_53 AC 138 ms
78,836 KB
testcase_54 AC 134 ms
78,536 KB
testcase_55 AC 245 ms
96,532 KB
testcase_56 AC 271 ms
98,504 KB
testcase_57 AC 285 ms
99,888 KB
testcase_58 AC 188 ms
88,560 KB
testcase_59 AC 308 ms
101,836 KB
testcase_60 AC 38 ms
54,400 KB
testcase_61 AC 38 ms
54,980 KB
testcase_62 AC 41 ms
54,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

INF = 1 << 60

n, m = map(int, input().split())

g = [[] for _ in range(n)]
for _ in range(m):
  u, v = map(int, input().split())
  u -= 1
  v -= 1
  g[u].append(v)
  g[v].append(u)

q = int(input())
for _ in range(q):
  src = int(input())
  src -= 1

  dist = [INF for _ in range(n)]
  dist[src] = 0
  dq = deque()
  dq.append(src)
  while len(dq) > 0:
    cur = dq.popleft()
    for nxt in g[cur]:
      if dist[nxt] < INF:
        continue
      dist[nxt] = dist[cur] + 1
      dq.append(nxt)

  cnt = 0
  day = - INF
  for v in range(n):
    if v == src:
      continue

    if dist[v] < INF:
      cnt += 1
      if dist[v] >= 2:
        day = max(day, dist[v])

  if day == - INF:
    print(f"{cnt} 0")
  else:
    day = (day - 1).bit_length()
    print(f"{cnt} {day}")
0