結果

問題 No.583 鉄道同好会
ユーザー 👑 rin204rin204
提出日時 2022-07-06 07:21:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 80,212 KB
最終ジャッジ日時 2024-05-10 04:23:34
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,400 KB
testcase_01 AC 38 ms
53,380 KB
testcase_02 AC 39 ms
52,376 KB
testcase_03 AC 37 ms
52,720 KB
testcase_04 AC 39 ms
53,500 KB
testcase_05 AC 38 ms
53,076 KB
testcase_06 AC 40 ms
52,876 KB
testcase_07 AC 38 ms
53,572 KB
testcase_08 AC 40 ms
53,236 KB
testcase_09 AC 39 ms
53,200 KB
testcase_10 AC 42 ms
54,168 KB
testcase_11 AC 90 ms
76,832 KB
testcase_12 AC 94 ms
77,184 KB
testcase_13 AC 95 ms
77,872 KB
testcase_14 AC 95 ms
77,184 KB
testcase_15 AC 102 ms
77,264 KB
testcase_16 AC 137 ms
80,212 KB
testcase_17 AC 144 ms
80,204 KB
testcase_18 AC 141 ms
80,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append(v)
    edges[v].append(u)

stack = [u]
used = [False] * n
used[u] = True
while stack:
    pos = stack.pop()
    for npos in edges[pos]:
        if used[npos]:
            continue
        used[npos] = True
        stack.append(npos)
odd = 0
for i in range(n):
    if not used[i] and edges[i]:
        print("NO")
        exit()
    if len(edges[i]) & 1:
        odd += 1
if odd <= 2:
    print("YES")
else:
    print("NO")
0