結果

問題 No.812 Change of Class
ユーザー buey_tbuey_t
提出日時 2023-04-01 15:45:24
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,586 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,544 KB
実行使用メモリ 534,984 KB
最終ジャッジ日時 2023-10-24 18:13:54
合計ジャッジ時間 17,055 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 429 ms
110,544 KB
testcase_02 AC 760 ms
185,000 KB
testcase_03 AC 1,418 ms
270,960 KB
testcase_04 AC 1,404 ms
270,488 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 145 ms
98,188 KB
testcase_08 AC 134 ms
88,704 KB
testcase_09 AC 3,374 ms
266,400 KB
testcase_10 AC 3,602 ms
267,560 KB
testcase_11 AC 232 ms
127,828 KB
testcase_12 AC 1,983 ms
265,796 KB
testcase_13 AC 127 ms
84,128 KB
testcase_14 AC 125 ms
84,132 KB
testcase_15 AC 2,449 ms
262,632 KB
testcase_16 AC 343 ms
95,880 KB
testcase_17 AC 2,122 ms
263,156 KB
testcase_18 AC 1,690 ms
216,652 KB
testcase_19 AC 1,914 ms
261,388 KB
testcase_20 AC 3,624 ms
266,764 KB
testcase_21 AC 1,560 ms
204,324 KB
testcase_22 AC 789 ms
131,612 KB
testcase_23 AC 304 ms
94,556 KB
testcase_24 AC 367 ms
98,028 KB
testcase_25 AC 656 ms
122,024 KB
testcase_26 AC 3,109 ms
265,076 KB
testcase_27 AC 2,601 ms
265,536 KB
testcase_28 AC 1,768 ms
253,616 KB
testcase_29 AC 575 ms
110,820 KB
testcase_30 AC 2,306 ms
263,160 KB
testcase_31 AC 2,165 ms
264,212 KB
testcase_32 AC 942 ms
145,248 KB
testcase_33 AC 2,344 ms
262,364 KB
testcase_34 AC 346 ms
97,100 KB
testcase_35 AC 515 ms
114,172 KB
testcase_36 AC 356 ms
98,840 KB
testcase_37 AC 1,188 ms
168,784 KB
testcase_38 AC 278 ms
105,164 KB
testcase_39 AC 1,183 ms
170,948 KB
testcase_40 AC 396 ms
102,488 KB
testcase_41 AC 178 ms
99,488 KB
testcase_42 AC 2,304 ms
265,796 KB
testcase_43 AC 358 ms
116,028 KB
testcase_44 AC 1,622 ms
254,308 KB
testcase_45 AC 355 ms
98,932 KB
testcase_46 AC 349 ms
117,412 KB
testcase_47 AC 1,616 ms
250,352 KB
testcase_48 AC 1,582 ms
235,348 KB
testcase_49 AC 636 ms
120,708 KB
testcase_50 AC 201 ms
90,088 KB
testcase_51 AC 510 ms
116,832 KB
testcase_52 AC 790 ms
144,696 KB
testcase_53 AC 471 ms
105,288 KB
testcase_54 AC 449 ms
104,376 KB
testcase_55 AC 1,960 ms
266,236 KB
testcase_56 AC 2,327 ms
268,068 KB
testcase_57 AC 2,417 ms
270,104 KB
testcase_58 AC 1,526 ms
245,952 KB
testcase_59 AC 2,829 ms
272,816 KB
testcase_60 AC 187 ms
84,100 KB
testcase_61 AC 125 ms
84,104 KB
testcase_62 AC 130 ms
84,104 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())
    
    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()
0