結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
buey_t
|
| 提出日時 | 2023-04-01 15:45:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,586 bytes |
| コンパイル時間 | 186 ms |
| コンパイル使用メモリ | 82,472 KB |
| 実行使用メモリ | 531,412 KB |
| 最終ジャッジ日時 | 2024-09-24 11:04:46 |
| 合計ジャッジ時間 | 15,205 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 4 TLE * 1 MLE * 1 -- * 54 |
ソースコード
def main():
from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from collections import deque,Counter,defaultdict
from itertools import permutations,combinations
from decimal import Decimal,ROUND_HALF_UP
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import lru_cache, reduce
#@lru_cache(maxsize=None)
from operator import add,sub,mul,xor,and_,or_,itemgetter
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353
#DecimalならPython
#再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!
'''
クエリが少ない
各クエリごとにダイクストラでよい
そいつ以外のやつも友達になる
だから、自分だけ考えればいいわけではない
dpっぽさはあるな
'''
N,M = map(int, input().split())
try:
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
except:
pass
try:
import sys
sys.setrecursionlimit(10**7)
except:
pass
G = [[] for _ in range(N+1)]
memo = [set() for _ in range(N+1)]
for _ in range(M):
p,q = map(int, input().split())
G[p].append(q)
G[q].append(p)
memo[p].add(q)
memo[q].add(p)
ans = [(-1,0)]*(N+1)
q = int(input())
for _ in range(q):
A = int(input())
if ans[A][0] != -1:
print(*ans[A])
continue
seen = [0]*(N+1)
Q = []
heappush(Q,(-1,A))
while len(Q) > 0:
cnt,pos = heappop(Q)
if seen[pos] == 1:
continue
memo[A].add(pos)
seen[pos] = 1
if len(memo[A])-1 > ans[A][0]:
ans[A] = (len(memo[A])-1,cnt)
for nx in G[pos]:
if seen[nx] == 0:
heappush(Q,(cnt+1,nx))
tmp = ans[A][1]
cnt = 0
while tmp > 0:
cnt += 1
tmp //= 2
ans[A] = (ans[A][0],cnt)
print(*ans[A])
if __name__ == '__main__':
main()
buey_t