結果

問題 No.1473 おでぶなおばけさん
ユーザー buey_tbuey_t
提出日時 2023-03-26 10:23:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,410 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 118,836 KB
最終ジャッジ日時 2023-10-19 13:24:50
合計ジャッジ時間 26,673 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
88,172 KB
testcase_01 AC 150 ms
88,176 KB
testcase_02 AC 726 ms
115,904 KB
testcase_03 AC 654 ms
111,816 KB
testcase_04 AC 562 ms
105,196 KB
testcase_05 AC 372 ms
95,476 KB
testcase_06 AC 639 ms
113,636 KB
testcase_07 AC 798 ms
117,616 KB
testcase_08 AC 861 ms
118,496 KB
testcase_09 AC 765 ms
117,740 KB
testcase_10 AC 382 ms
102,792 KB
testcase_11 AC 382 ms
102,568 KB
testcase_12 AC 380 ms
102,568 KB
testcase_13 AC 297 ms
96,164 KB
testcase_14 AC 260 ms
95,596 KB
testcase_15 AC 365 ms
99,648 KB
testcase_16 AC 378 ms
103,028 KB
testcase_17 AC 181 ms
89,388 KB
testcase_18 AC 190 ms
89,388 KB
testcase_19 AC 474 ms
101,800 KB
testcase_20 AC 658 ms
109,864 KB
testcase_21 AC 667 ms
107,760 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 705 ms
117,208 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 725 ms
118,836 KB
testcase_32 AC 559 ms
113,400 KB
testcase_33 AC 621 ms
109,352 KB
testcase_34 AC 492 ms
100,388 KB
testcase_35 AC 415 ms
100,848 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 376 ms
102,796 KB
testcase_40 AC 371 ms
102,552 KB
testcase_41 AC 390 ms
103,488 KB
testcase_42 AC 389 ms
103,484 KB
testcase_43 AC 313 ms
106,040 KB
testcase_44 AC 313 ms
106,044 KB
testcase_45 AC 311 ms
105,984 KB
testcase_46 AC 726 ms
109,608 KB
testcase_47 AC 819 ms
113,612 KB
testcase_48 AC 694 ms
111,740 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]
        
        uf.union(u,v)
        mx = w
        G[u].append(v)
        G[v].append(u)
        
        if uf.same(1,N):
            break
    
    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