結果

問題 No.1473 おでぶなおばけさん
ユーザー buey_tbuey_t
提出日時 2023-03-26 10:25:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 732 ms / 2,000 ms
コード長 3,422 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 119,244 KB
最終ジャッジ日時 2024-09-19 09:34:20
合計ジャッジ時間 23,534 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
89,088 KB
testcase_01 AC 140 ms
89,216 KB
testcase_02 AC 650 ms
117,440 KB
testcase_03 AC 559 ms
111,768 KB
testcase_04 AC 479 ms
105,612 KB
testcase_05 AC 324 ms
95,672 KB
testcase_06 AC 553 ms
113,956 KB
testcase_07 AC 716 ms
119,244 KB
testcase_08 AC 732 ms
118,516 KB
testcase_09 AC 637 ms
117,952 KB
testcase_10 AC 333 ms
103,200 KB
testcase_11 AC 326 ms
103,076 KB
testcase_12 AC 343 ms
103,040 KB
testcase_13 AC 266 ms
96,752 KB
testcase_14 AC 241 ms
96,012 KB
testcase_15 AC 314 ms
101,120 KB
testcase_16 AC 338 ms
103,552 KB
testcase_17 AC 176 ms
90,240 KB
testcase_18 AC 182 ms
90,216 KB
testcase_19 AC 432 ms
101,984 KB
testcase_20 AC 585 ms
110,796 KB
testcase_21 AC 579 ms
108,544 KB
testcase_22 AC 593 ms
114,424 KB
testcase_23 AC 484 ms
110,848 KB
testcase_24 AC 537 ms
111,212 KB
testcase_25 AC 611 ms
113,856 KB
testcase_26 AC 611 ms
113,736 KB
testcase_27 AC 360 ms
98,368 KB
testcase_28 AC 603 ms
117,652 KB
testcase_29 AC 448 ms
107,360 KB
testcase_30 AC 472 ms
108,948 KB
testcase_31 AC 591 ms
119,040 KB
testcase_32 AC 462 ms
112,992 KB
testcase_33 AC 527 ms
110,324 KB
testcase_34 AC 395 ms
100,892 KB
testcase_35 AC 353 ms
101,552 KB
testcase_36 AC 463 ms
107,632 KB
testcase_37 AC 505 ms
109,864 KB
testcase_38 AC 283 ms
94,316 KB
testcase_39 AC 331 ms
102,912 KB
testcase_40 AC 347 ms
103,296 KB
testcase_41 AC 342 ms
103,924 KB
testcase_42 AC 332 ms
103,776 KB
testcase_43 AC 278 ms
106,692 KB
testcase_44 AC 279 ms
106,496 KB
testcase_45 AC 278 ms
106,496 KB
testcase_46 AC 673 ms
110,336 KB
testcase_47 AC 682 ms
113,600 KB
testcase_48 AC 572 ms
112,384 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!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    
    '''
    
    
    
    '''
    
    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n
            #親だけ
            self.edge = [0]*n
    
        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]
    
        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)
    
            if self.parents[x] > self.parents[y]:
                x, y = y, x
            
            self.edge[x] += 1
            
            if x == y:
                return
    
            self.parents[x] += self.parents[y]
            self.edge[x] += self.edge[y]
            self.parents[y] = x
    
        def size(self, x):
            return -self.parents[self.find(x)]
    
        def same(self, x, y):
            return self.find(x) == self.find(y)
    
        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]
    
        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]
    
        def group_count(self):
            return len(self.roots())
    
        def all_group_members(self):
            group_members = defaultdict(list)
            for member in range(self.n):
                group_members[self.find(member)].append(member)
            return group_members
    
        def __str__(self):
            return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items())
    
    N,M = map(int, input().split())
    
    uf = UnionFind(N+1)

    edge = []
    
    for _ in range(M):
        u,v,w = map(int, input().split())
        edge.append((u,v,w))
    
    edge.sort(lambda x:x[2],reverse=True)
    G = [[] for _ in range(N+1)]
    
    mx = 0
    for i in range(M):
        u,v,w = edge[i]
        
        if uf.same(1,N) and mx != w:
            break
        
        uf.union(u,v)
        mx = w
        G[u].append(v)
        G[v].append(u)
    
    Q = deque()
    Q.append((1,0))
    seen = [0]*(N+1)
    
    while len(Q) > 0:
        pos,cnt = Q.popleft()
        if seen[pos] == 1:
            continue
        
        if pos == N:
            print(mx,cnt)
            exit()
        
        seen[pos] = 1
        
        for nx in G[pos]:
            if seen[nx] == 0:
                Q.append((nx,cnt+1))
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0