結果

問題 No.583 鉄道同好会
コンテスト
ユーザー roaris
提出日時 2019-08-04 20:02:24
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 489 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 394 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 19,064 KB
最終ジャッジ日時 2026-03-30 16:44:17
合計ジャッジ時間 6,034 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict

N, M = map(int, input().split())
adj_dict = defaultdict(list)

for _ in range(M):
    Sa_i, Sb_i = map(int, input().split())
    adj_dict[Sa_i].append(Sb_i)
    adj_dict[Sb_i].append(Sa_i)

d1, d2 = 0, 0

for node in adj_dict:
    d = len(adj_dict[node])
    
    if d == 1:
        d1 += 1
    elif d == 2:
        d2 += 1
    else:
        print('NO')
        exit()
    
if d1 == 2 and d2 == len(adj_dict) - 2:
    print('YES')
else:
    print('NO')
0