結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,556 KB
testcase_01 AC 19 ms
8,628 KB
testcase_02 AC 20 ms
8,516 KB
testcase_03 AC 20 ms
8,628 KB
testcase_04 AC 20 ms
8,508 KB
testcase_05 AC 19 ms
8,620 KB
testcase_06 WA -
testcase_07 AC 19 ms
8,656 KB
testcase_08 AC 19 ms
8,636 KB
testcase_09 AC 19 ms
8,488 KB
testcase_10 AC 23 ms
8,576 KB
testcase_11 AC 353 ms
13,372 KB
testcase_12 AC 484 ms
15,348 KB
testcase_13 AC 481 ms
15,308 KB
testcase_14 AC 482 ms
15,484 KB
testcase_15 AC 621 ms
17,436 KB
testcase_16 AC 1,193 ms
25,300 KB
testcase_17 AC 1,432 ms
28,992 KB
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.py:31: SyntaxWarning: invalid decimal literal
  return "YES" if oddcount <= 2 and len(unionset) == 1else "NO"

ソースコード

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) == 1else "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