結果

問題 No.583 鉄道同好会
ユーザー mitsuomitsuo
提出日時 2017-12-31 17:16:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 949 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 29,024 KB
最終ジャッジ日時 2023-08-23 12:31:46
合計ジャッジ時間 7,849 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,716 KB
testcase_01 AC 19 ms
8,520 KB
testcase_02 AC 19 ms
8,476 KB
testcase_03 AC 19 ms
8,396 KB
testcase_04 AC 19 ms
8,480 KB
testcase_05 AC 19 ms
8,480 KB
testcase_06 WA -
testcase_07 AC 18 ms
8,480 KB
testcase_08 AC 19 ms
8,500 KB
testcase_09 AC 19 ms
8,396 KB
testcase_10 AC 22 ms
8,744 KB
testcase_11 AC 353 ms
13,416 KB
testcase_12 AC 479 ms
15,512 KB
testcase_13 AC 486 ms
15,252 KB
testcase_14 AC 488 ms
15,504 KB
testcase_15 AC 623 ms
17,388 KB
testcase_16 AC 1,177 ms
25,312 KB
testcase_17 AC 1,441 ms
29,024 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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))
0