結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-12 22:15:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,186 ms / 4,000 ms |
| コード長 | 887 bytes |
| コンパイル時間 | 199 ms |
| コンパイル使用メモリ | 82,172 KB |
| 実行使用メモリ | 268,300 KB |
| 最終ジャッジ日時 | 2024-06-12 18:58:47 |
| 合計ジャッジ時間 | 26,832 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
import sys
from collections import deque
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
a-=1;b-=1
g[a].append(b)
g[b].append(a)
q = int(input())
a = []
for i in range(q):
a.append(int(input())-1)
kyori = [1<<30]*n
ok = [0]*n
def dfs(x,y):
for i in g[x]:
if kyori[i] > y+1:
kyori[i] = y+1
ok[i] = 1
que.append([i,y+1])
for i in range(q):
b = a[i]
kyori = [1<<30]*n
ok = [0]*n
ok[b] = 1
kyori[b] = 0
que = deque([[b,0]])
while que:
x,y = que.popleft()
dfs(x,y)
ans = 0
for j in kyori:
if j != 1<<30:
ans = max(ans,j)
ans2 = 0
if ans:
ans-=1
while ans:
ans//=2
ans2+=1
print(sum(ok)-1,ans2)