結果

問題 No.583 鉄道同好会
ユーザー lloyzlloyz
提出日時 2022-09-29 00:51:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 15,324 KB
最終ジャッジ日時 2023-08-24 04:41:34
合計ジャッジ時間 3,580 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,516 KB
testcase_01 AC 19 ms
8,532 KB
testcase_02 AC 18 ms
8,432 KB
testcase_03 AC 18 ms
8,520 KB
testcase_04 AC 19 ms
8,544 KB
testcase_05 AC 18 ms
8,564 KB
testcase_06 AC 18 ms
8,500 KB
testcase_07 AC 18 ms
8,440 KB
testcase_08 AC 18 ms
8,656 KB
testcase_09 AC 18 ms
8,492 KB
testcase_10 AC 19 ms
8,564 KB
testcase_11 AC 115 ms
10,304 KB
testcase_12 AC 152 ms
11,008 KB
testcase_13 AC 152 ms
10,924 KB
testcase_14 AC 153 ms
10,908 KB
testcase_15 AC 192 ms
11,636 KB
testcase_16 AC 350 ms
14,276 KB
testcase_17 AC 423 ms
15,276 KB
testcase_18 AC 429 ms
15,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n, m = map(int, input().split())
Edge = defaultdict(list)
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    Edge[u].append(v)
    Edge[v].append(u)
Stack = [u]
seen = set([u])
while Stack:
    cp = Stack.pop()
    for np in Edge[cp]:
        if np in seen:
            continue
        seen.add(np)
        Stack.append(np)

odd_n = 0
for i in range(n):
    if i not in seen and Edge[i]:
        print("NO")
        exit()
    if len(Edge[i]) % 2 == 1:
        odd_n += 1
if odd_n <= 2:
    print("YES")
else:
    print("NO")
0