結果

問題 No.1473 おでぶなおばけさん
ユーザー ntudantuda
提出日時 2022-03-12 15:29:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 666 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 81,764 KB
実行使用メモリ 131,304 KB
最終ジャッジ日時 2023-10-16 22:54:24
合計ジャッジ時間 20,362 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,596 KB
testcase_01 AC 39 ms
55,596 KB
testcase_02 AC 666 ms
125,648 KB
testcase_03 AC 511 ms
118,464 KB
testcase_04 AC 357 ms
103,344 KB
testcase_05 AC 253 ms
82,340 KB
testcase_06 AC 502 ms
111,636 KB
testcase_07 AC 554 ms
127,884 KB
testcase_08 AC 565 ms
131,304 KB
testcase_09 AC 519 ms
126,692 KB
testcase_10 AC 251 ms
86,292 KB
testcase_11 AC 249 ms
86,296 KB
testcase_12 AC 249 ms
86,280 KB
testcase_13 AC 181 ms
82,412 KB
testcase_14 AC 151 ms
80,500 KB
testcase_15 AC 240 ms
89,404 KB
testcase_16 AC 247 ms
86,240 KB
testcase_17 AC 81 ms
76,632 KB
testcase_18 AC 87 ms
76,660 KB
testcase_19 AC 334 ms
88,172 KB
testcase_20 AC 535 ms
111,468 KB
testcase_21 AC 491 ms
96,944 KB
testcase_22 AC 459 ms
116,240 KB
testcase_23 AC 342 ms
111,704 KB
testcase_24 AC 411 ms
107,448 KB
testcase_25 AC 453 ms
115,776 KB
testcase_26 AC 457 ms
117,508 KB
testcase_27 AC 233 ms
83,700 KB
testcase_28 AC 489 ms
124,040 KB
testcase_29 AC 389 ms
101,500 KB
testcase_30 AC 438 ms
104,740 KB
testcase_31 AC 550 ms
124,592 KB
testcase_32 AC 482 ms
114,724 KB
testcase_33 AC 469 ms
106,704 KB
testcase_34 AC 388 ms
91,316 KB
testcase_35 AC 282 ms
90,144 KB
testcase_36 AC 348 ms
95,516 KB
testcase_37 AC 358 ms
114,012 KB
testcase_38 AC 178 ms
80,392 KB
testcase_39 AC 254 ms
86,472 KB
testcase_40 AC 244 ms
86,456 KB
testcase_41 AC 245 ms
86,408 KB
testcase_42 AC 252 ms
86,416 KB
testcase_43 AC 203 ms
95,848 KB
testcase_44 AC 208 ms
95,836 KB
testcase_45 AC 203 ms
95,856 KB
testcase_46 AC 419 ms
105,204 KB
testcase_47 AC 479 ms
111,432 KB
testcase_48 AC 444 ms
108,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(100010)

def root(x):
    if P[x] < 0:
        return x
    else:
        P[x] = root(P[x])  # 経路圧縮
        return P[x]

def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y: return
    P[x] += P[y]
    P[y] = x

def same(x, y):
    return root(x) == root(y)

n, m = map(int, input().split())
STD = [list(map(int, input().split())) for _ in range(m)]
STD.sort(key=lambda x: (-x[2]))
P = [-1] * (n + 1)
E = [[] for _ in range(n + 1)]
nowd = 10 ** 10
flag = 1
for i, (s, t, d) in enumerate(STD):
    if flag == 1:
        if nowd > d:
            nowd = d
        unite(s, t)
        E[s].append(t)
        E[t].append(s)
        if same(1, n):
            flag = 0
    else:
        if d != nowd:
            break
        else:
            unite(s, t)
            E[s].append(t)
            E[t].append(s)

from collections import deque

q1 = deque()
cnt = 0
q1.append(1)
visited = [0] * (n + 1)
visited[1] = 1
while len(q1) > 0:
    cnt += 1
    q2 = deque()
    while len(q1) > 0:
        p = q1.pop()
        for x in E[p]:
            if x == n:
                print(nowd, cnt)
                exit()
            if visited[x] == 0:
                visited[x] = 1
                q2.append(x)
    q1 = q2
0