結果
| 問題 |
No.583 鉄道同好会
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-31 17:16:50 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 949 bytes |
| コンパイル時間 | 354 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 31,232 KB |
| 最終ジャッジ日時 | 2024-12-21 15:30:09 |
| 合計ジャッジ時間 | 9,725 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 2 |
ソースコード
import collections
def solve(N, M, data):
count = collections.Counter()
unionset = []
for d in data:
count.update(d)
d0s = None
d1s = None
for s in unionset:
if d[0] in s:
d0s = s
elif d[1] in s:
d1s = s
if d0s == None and d1s == None:
unionset.append(set([d[0], d[1]]))
elif d0s != None and d1s == None:
d0s.add(d[1])
elif d0s == None and d1s != None:
d1s.add(d[0])
else:
unionset.remove(d0s)
d0s.union(d1s)
oddcount = 0
for val in count.values():
if val % 2 == 1:
oddcount += 1
return "YES" if oddcount <= 2 and len(unionset) == 1 else "NO"
if __name__ == '__main__':
N, M = map(int, input().split())
d = []
for _ in range(0, M):
d.append(list(map(int, input().split())))
print(solve(N, M, d))