結果

問題 No.583 鉄道同好会
ユーザー maspymaspy
提出日時 2020-02-28 11:45:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 778 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 31,088 KB
最終ジャッジ日時 2024-04-21 17:28:59
合計ジャッジ時間 2,227 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,624 KB
testcase_01 AC 25 ms
10,624 KB
testcase_02 AC 25 ms
10,752 KB
testcase_03 AC 24 ms
10,624 KB
testcase_04 AC 25 ms
10,496 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 26 ms
10,752 KB
testcase_09 AC 30 ms
10,624 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 59 ms
15,440 KB
testcase_12 AC 68 ms
17,480 KB
testcase_13 AC 66 ms
17,344 KB
testcase_14 AC 69 ms
17,344 KB
testcase_15 AC 81 ms
19,628 KB
testcase_16 AC 132 ms
27,688 KB
testcase_17 AC 157 ms
31,088 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
N, M = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

# %%
G = [[] for _ in range(N)]
for a, b in AB:
    G[a].append(b)
    G[b].append(a)

# %%
deg = [len(x) for x in G]
comp = [0] * N
next_c = 1
for v in range(N):
    if deg[v] == 0 or comp[v]:
        continue
    comp[v] = next_c
    next_c += 1
    stack = [v]
    while stack:
        v = stack.pop()
        for w in G[v]:
            if not comp[w]:
                comp[w] = comp[v]
                stack.append(w)

# %%
odd_pt_cnt = sum(x & 2 for x in deg)
is_euler = odd_pt_cnt <= 2 and max(comp) <= 1
print('YES' if is_euler else 'NO')
0