結果

問題 No.812 Change of Class
ユーザー buey_tbuey_t
提出日時 2023-04-01 15:52:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,674 ms / 4,000 ms
コード長 2,419 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 81,600 KB
実行使用メモリ 310,388 KB
最終ジャッジ日時 2023-10-24 18:16:12
合計ジャッジ時間 40,425 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 755 ms
267,644 KB
testcase_01 AC 260 ms
112,712 KB
testcase_02 AC 477 ms
172,916 KB
testcase_03 AC 886 ms
304,492 KB
testcase_04 AC 908 ms
278,844 KB
testcase_05 AC 1,674 ms
297,268 KB
testcase_06 AC 1,253 ms
245,232 KB
testcase_07 AC 136 ms
89,240 KB
testcase_08 AC 134 ms
88,744 KB
testcase_09 AC 1,437 ms
253,836 KB
testcase_10 AC 1,485 ms
258,812 KB
testcase_11 AC 197 ms
100,956 KB
testcase_12 AC 884 ms
218,512 KB
testcase_13 AC 121 ms
84,096 KB
testcase_14 AC 120 ms
84,100 KB
testcase_15 AC 1,040 ms
228,884 KB
testcase_16 AC 241 ms
93,716 KB
testcase_17 AC 894 ms
212,608 KB
testcase_18 AC 687 ms
171,104 KB
testcase_19 AC 789 ms
206,288 KB
testcase_20 AC 1,541 ms
265,556 KB
testcase_21 AC 712 ms
162,928 KB
testcase_22 AC 424 ms
126,732 KB
testcase_23 AC 226 ms
92,380 KB
testcase_24 AC 248 ms
95,716 KB
testcase_25 AC 359 ms
119,360 KB
testcase_26 AC 1,275 ms
254,140 KB
testcase_27 AC 1,137 ms
234,952 KB
testcase_28 AC 768 ms
201,736 KB
testcase_29 AC 311 ms
105,896 KB
testcase_30 AC 959 ms
229,348 KB
testcase_31 AC 835 ms
207,328 KB
testcase_32 AC 487 ms
135,940 KB
testcase_33 AC 1,079 ms
230,180 KB
testcase_34 AC 252 ms
93,936 KB
testcase_35 AC 327 ms
116,940 KB
testcase_36 AC 244 ms
96,148 KB
testcase_37 AC 598 ms
165,556 KB
testcase_38 AC 169 ms
90,620 KB
testcase_39 AC 573 ms
162,972 KB
testcase_40 AC 268 ms
100,816 KB
testcase_41 AC 162 ms
90,468 KB
testcase_42 AC 1,044 ms
247,380 KB
testcase_43 AC 295 ms
114,896 KB
testcase_44 AC 808 ms
223,952 KB
testcase_45 AC 240 ms
96,044 KB
testcase_46 AC 263 ms
111,308 KB
testcase_47 AC 789 ms
229,800 KB
testcase_48 AC 748 ms
207,600 KB
testcase_49 AC 348 ms
120,580 KB
testcase_50 AC 163 ms
88,956 KB
testcase_51 AC 321 ms
121,376 KB
testcase_52 AC 439 ms
147,192 KB
testcase_53 AC 280 ms
104,536 KB
testcase_54 AC 281 ms
102,536 KB
testcase_55 AC 687 ms
263,216 KB
testcase_56 AC 781 ms
309,700 KB
testcase_57 AC 1,003 ms
310,388 KB
testcase_58 AC 476 ms
182,392 KB
testcase_59 AC 897 ms
307,772 KB
testcase_60 AC 123 ms
84,096 KB
testcase_61 AC 123 ms
84,096 KB
testcase_62 AC 124 ms
84,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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())
    
    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)
    
    ans1 = [-1]*(N+1)
    ans2 = [0]*(N+1)
    
    q = int(input())
    for _ in range(q):
        A = int(input())
        if ans1[A] != -1:
            print(ans1[A],ans2[A])
            continue
        
        seen = set()
        
        Q = deque()
        Q.append((-1,A))
        
        while len(Q) > 0:
            cnt,pos = Q.popleft()
            if pos in seen:
                continue
            
            memo[A].add(pos)
            seen.add(pos)
            
            if len(memo[A])-1 > ans1[A]:
                ans1[A] = len(memo[A])-1
                ans2[A] = cnt
            
            for nx in G[pos]:
                if nx not in seen:
                    Q.append((cnt+1,nx))
        
        tmp = ans2[A]
        cnt = 0
        while tmp > 0:
            cnt += 1
            tmp //= 2
            
        ans2[A] = cnt
        print(ans1[A],ans2[A])
        
        
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0