結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 KazunKazun
提出日時 2021-04-09 23:59:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 708 ms / 2,000 ms
コード長 2,801 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 108,236 KB
最終ジャッジ日時 2023-09-07 18:59:50
合計ジャッジ時間 20,458 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
71,472 KB
testcase_01 AC 100 ms
71,316 KB
testcase_02 AC 572 ms
108,236 KB
testcase_03 AC 508 ms
97,188 KB
testcase_04 AC 389 ms
88,808 KB
testcase_05 AC 250 ms
83,032 KB
testcase_06 AC 464 ms
97,884 KB
testcase_07 AC 648 ms
105,100 KB
testcase_08 AC 708 ms
108,164 KB
testcase_09 AC 605 ms
104,172 KB
testcase_10 AC 316 ms
91,556 KB
testcase_11 AC 296 ms
89,108 KB
testcase_12 AC 296 ms
88,860 KB
testcase_13 AC 238 ms
87,428 KB
testcase_14 AC 185 ms
82,656 KB
testcase_15 AC 278 ms
88,736 KB
testcase_16 AC 293 ms
88,640 KB
testcase_17 AC 118 ms
77,604 KB
testcase_18 AC 125 ms
77,688 KB
testcase_19 AC 338 ms
88,552 KB
testcase_20 AC 512 ms
100,760 KB
testcase_21 AC 469 ms
95,412 KB
testcase_22 AC 409 ms
99,948 KB
testcase_23 AC 403 ms
96,460 KB
testcase_24 AC 371 ms
95,500 KB
testcase_25 AC 402 ms
99,748 KB
testcase_26 AC 390 ms
97,852 KB
testcase_27 AC 242 ms
86,384 KB
testcase_28 AC 536 ms
106,712 KB
testcase_29 AC 374 ms
94,628 KB
testcase_30 AC 384 ms
99,620 KB
testcase_31 AC 460 ms
102,748 KB
testcase_32 AC 367 ms
100,820 KB
testcase_33 AC 400 ms
99,100 KB
testcase_34 AC 318 ms
90,296 KB
testcase_35 AC 263 ms
89,832 KB
testcase_36 AC 322 ms
91,020 KB
testcase_37 AC 368 ms
95,988 KB
testcase_38 AC 191 ms
80,464 KB
testcase_39 AC 292 ms
88,948 KB
testcase_40 AC 294 ms
88,980 KB
testcase_41 AC 293 ms
88,584 KB
testcase_42 AC 289 ms
88,488 KB
testcase_43 AC 236 ms
94,488 KB
testcase_44 AC 236 ms
94,188 KB
testcase_45 AC 235 ms
94,404 KB
testcase_46 AC 471 ms
94,728 KB
testcase_47 AC 600 ms
100,788 KB
testcase_48 AC 484 ms
96,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Union_Find():
    def __init__(self,N):
        """0,1,...,n-1を要素として初期化する.

        N:要素数
        """
        self.n=N
        self.parents=[-1]*N
        self.rank=[0]*N

    def find(self, x):
        """要素xの属している族を調べる.

        x:要素
        """
        V=[]
        while self.parents[x]>=0:
            V.append(x)
            x=self.parents[x]

        for v in V:
            self.parents[v]=x
        return x

    def union(self, x, y):
        """要素x,yを同一視する.

        x,y:要素
        """
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return

        if self.rank[x]<self.rank[y]:
            x,y=y,x

        self.parents[x]+=self.parents[y]
        self.parents[y]=x

        if self.rank[x]==self.rank[y]:
            self.rank[x]+=1

    def size(self, x):
        """要素xの属している要素の数.

        x:要素
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x,yは同一視されているか?

        x,y:要素
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属している族の要素.
        ※族の要素の個数が欲しいときはsizeを使うこと!!

        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):
        """全ての族の出力
        """
        X={r:[] for r in self.roots()}
        for k in range(self.n):
            X[self.find(k)].append(k)
        return X

    def refresh(self):
        for i in range(self.n):
            _=self.find(i)

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def __repr__(self):
        return self.__str__()
#================================================
from collections import deque
import sys
input=sys.stdin.readline

N,M=map(int,input().split())
E=[]
for _ in range(M):
    s,t,d=map(int,input().split())
    E.append((s,t,d))

E.sort(key=lambda x:x[-1],reverse=True)
U=Union_Find(N+1)
for s,t,d in E:
    U.union(s,t)
    if U.same(1,N):
        w=d
        break

A=[[] for _ in range(N+1)]
for s,t,d in E:
    if w<=d:
        A[s].append(t)
        A[t].append(s)

T=[-1]*(N+1)
T[1]=0
Q=deque([1])
while True:
    x=Q.popleft()
    for y in A[x]:
        if T[y]==-1:
            Q.append(y)
            T[y]=T[x]+1

        if y==N:
            print(w,T[y])
            exit()
0