結果

問題 No.583 鉄道同好会
コンテスト
ユーザー wajima_wataru
提出日時 2018-01-03 21:25:55
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,099 ms / 2,000 ms
+ 655µs
コード長 611 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 71 ms
コンパイル使用メモリ 15,104 KB
実行使用メモリ 17,920 KB
最終ジャッジ日時 2026-10-14 19:07:30
合計ジャッジ時間 7,419 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, M = map(int, input().split())
S = [True for _ in range(N)]
C = [False for _ in range(N)]
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    S[a] = not(S[a])
    S[b] = not(S[b])
    G[a].append(b)
    G[b].append(a)
    C[a] = C[b] = True
    p = a


count = 0
for i, s in enumerate(S):
    if not s:
        count += 1
        p = i
       

def dfs(g, p, visited):
    visited.append(p)
    for n in g[p]:
        if n not in visited:
            dfs(g, n, visited)

visited = []
dfs(G, p, visited)
print('YES' if count <= 2 and len(visited) == C.count(True) else 'NO')
0