結果

問題 No.583 鉄道同好会
ユーザー roarisroaris
提出日時 2019-08-04 20:02:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 489 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 15,352 KB
最終ジャッジ日時 2023-09-23 00:53:53
合計ジャッジ時間 3,182 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,520 KB
testcase_01 AC 18 ms
8,616 KB
testcase_02 AC 19 ms
8,568 KB
testcase_03 AC 19 ms
8,488 KB
testcase_04 AC 18 ms
8,520 KB
testcase_05 AC 18 ms
8,544 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 18 ms
8,488 KB
testcase_09 AC 18 ms
8,516 KB
testcase_10 AC 20 ms
8,660 KB
testcase_11 AC 104 ms
10,124 KB
testcase_12 AC 139 ms
10,880 KB
testcase_13 AC 138 ms
10,824 KB
testcase_14 AC 137 ms
10,876 KB
testcase_15 AC 173 ms
11,608 KB
testcase_16 AC 307 ms
14,608 KB
testcase_17 AC 367 ms
15,304 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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