結果

問題 No.583 鉄道同好会
ユーザー maspymaspy
提出日時 2020-02-28 11:45:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 30,960 KB
最終ジャッジ日時 2024-04-21 17:29:02
合計ジャッジ時間 2,166 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 29 ms
10,624 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 AC 29 ms
10,752 KB
testcase_04 AC 29 ms
10,624 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 29 ms
10,624 KB
testcase_07 AC 29 ms
10,752 KB
testcase_08 AC 29 ms
10,752 KB
testcase_09 AC 29 ms
10,624 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 67 ms
15,568 KB
testcase_12 AC 80 ms
17,608 KB
testcase_13 AC 78 ms
17,596 KB
testcase_14 AC 78 ms
17,468 KB
testcase_15 AC 93 ms
19,632 KB
testcase_16 AC 153 ms
27,932 KB
testcase_17 AC 180 ms
30,960 KB
testcase_18 AC 183 ms
30,928 KB
権限があれば一括ダウンロードができます

ソースコード

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 & 1 for x in deg)
is_euler = odd_pt_cnt <= 2 and max(comp) <= 1
print('YES' if is_euler else 'NO')
0