結果

問題 No.812 Change of Class
ユーザー buey_tbuey_t
提出日時 2023-04-01 15:48:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,902 ms / 4,000 ms
コード長 2,375 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 81,604 KB
実行使用メモリ 298,480 KB
最終ジャッジ日時 2023-10-24 18:15:12
合計ジャッジ時間 24,927 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 798 ms
277,580 KB
testcase_01 AC 261 ms
111,204 KB
testcase_02 AC 486 ms
170,928 KB
testcase_03 AC 912 ms
298,480 KB
testcase_04 AC 893 ms
292,360 KB
testcase_05 AC 3,902 ms
275,288 KB
testcase_06 AC 3,695 ms
271,004 KB
testcase_07 AC 141 ms
88,936 KB
testcase_08 AC 139 ms
88,736 KB
testcase_09 AC 3,140 ms
274,224 KB
testcase_10 AC 3,282 ms
276,752 KB
testcase_11 AC 196 ms
100,048 KB
testcase_12 AC 1,947 ms
268,276 KB
testcase_13 AC 122 ms
84,088 KB
testcase_14 AC 122 ms
84,088 KB
testcase_15 AC 2,190 ms
265,624 KB
testcase_16 AC 393 ms
96,992 KB
testcase_17 AC 2,006 ms
270,288 KB
testcase_18 AC 1,563 ms
210,560 KB
testcase_19 AC 1,744 ms
265,396 KB
testcase_20 AC 3,345 ms
275,292 KB
testcase_21 AC 1,471 ms
198,036 KB
testcase_22 AC 759 ms
134,612 KB
testcase_23 AC 362 ms
95,384 KB
testcase_24 AC 434 ms
99,144 KB
testcase_25 AC 698 ms
125,864 KB
testcase_26 AC 3,038 ms
272,340 KB
testcase_27 AC 2,424 ms
269,160 KB
testcase_28 AC 1,722 ms
264,864 KB
testcase_29 AC 661 ms
112,068 KB
testcase_30 AC 2,259 ms
268,948 KB
testcase_31 AC 1,803 ms
266,492 KB
testcase_32 AC 942 ms
148,016 KB
testcase_33 AC 2,226 ms
266,984 KB
testcase_34 AC 447 ms
98,400 KB
testcase_35 AC 503 ms
118,644 KB
testcase_36 AC 364 ms
99,536 KB
testcase_37 AC 1,010 ms
175,424 KB
testcase_38 AC 171 ms
90,264 KB
testcase_39 AC 1,021 ms
174,460 KB
testcase_40 AC 423 ms
103,836 KB
testcase_41 AC 162 ms
90,144 KB
testcase_42 AC 2,023 ms
268,072 KB
testcase_43 AC 393 ms
114,132 KB
testcase_44 AC 1,475 ms
264,128 KB
testcase_45 AC 374 ms
100,012 KB
testcase_46 AC 360 ms
110,940 KB
testcase_47 AC 1,473 ms
264,528 KB
testcase_48 AC 1,348 ms
257,320 KB
testcase_49 AC 580 ms
126,424 KB
testcase_50 AC 242 ms
90,068 KB
testcase_51 AC 521 ms
119,232 KB
testcase_52 AC 688 ms
146,396 KB
testcase_53 AC 462 ms
108,252 KB
testcase_54 AC 456 ms
105,908 KB
testcase_55 AC 1,642 ms
271,196 KB
testcase_56 AC 1,906 ms
277,632 KB
testcase_57 AC 2,047 ms
275,424 KB
testcase_58 AC 1,073 ms
243,812 KB
testcase_59 AC 2,310 ms
286,960 KB
testcase_60 AC 123 ms
84,092 KB
testcase_61 AC 121 ms
84,092 KB
testcase_62 AC 121 ms
84,088 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)
    
    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 = set()
        
        Q = []
        heappush(Q,(-1,A))
        
        while len(Q) > 0:
            cnt,pos = heappop(Q)
            if pos in seen:
                continue
            
            memo[A].add(pos)
            seen.add(pos)
            
            if len(memo[A])-1 > ans[A][0]:
                ans[A] = (len(memo[A])-1,cnt)
            
            for nx in G[pos]:
                if nx not in seen:
                    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()
0