結果

問題 No.1565 Union
ユーザー 👑 H20H20
提出日時 2021-06-27 16:24:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 431 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 102,092 KB
最終ジャッジ日時 2023-09-07 18:03:06
合計ジャッジ時間 9,484 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,600 KB
testcase_01 AC 93 ms
71,548 KB
testcase_02 AC 94 ms
71,660 KB
testcase_03 AC 97 ms
71,700 KB
testcase_04 AC 96 ms
71,616 KB
testcase_05 AC 91 ms
71,528 KB
testcase_06 AC 96 ms
71,560 KB
testcase_07 AC 95 ms
71,660 KB
testcase_08 AC 93 ms
71,528 KB
testcase_09 AC 94 ms
71,740 KB
testcase_10 AC 211 ms
83,428 KB
testcase_11 AC 309 ms
94,668 KB
testcase_12 AC 306 ms
88,008 KB
testcase_13 AC 179 ms
82,680 KB
testcase_14 AC 367 ms
92,604 KB
testcase_15 WA -
testcase_16 AC 386 ms
99,336 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 262 ms
102,092 KB
testcase_21 AC 262 ms
101,812 KB
testcase_22 AC 262 ms
101,884 KB
testcase_23 AC 263 ms
101,700 KB
testcase_24 AC 263 ms
101,776 KB
testcase_25 WA -
testcase_26 AC 252 ms
99,860 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N,M = map(int, input().split())
L = [[] for _ in range(N+1)]
for i in range(M):
    a,b = map(int, input().split())
    L[b].append(a)
    L[a].append(b)

PASS = [False]*(N+1)

d = collections.deque()
d.append((1,0))

while len(d):
    p,cnt=d.pop()
    if p==N:
        print(cnt)
        exit()
    for n in L[p]:
        if PASS[n]==False:
            PASS[n]=True
            d.append((n,cnt+1))

print(-1)

0