結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー gew1fw
提出日時 2025-06-12 14:35:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 867 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 110,152 KB
最終ジャッジ日時 2025-06-12 14:35:51
合計ジャッジ時間 3,462 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    M = int(input[ptr])
    ptr += 1

    out_degree = [0] * (N + 1)
    in_degree = [0] * (N + 1)

    for _ in range(M):
        u = int(input[ptr])
        ptr += 1
        v = int(input[ptr])
        ptr += 1
        out_degree[u] += 1
        in_degree[v] += 1

    d = [0] * (N + 1)
    for i in range(1, N+1):
        d[i] = out_degree[i] - in_degree[i]

    S = 0
    for i in range(1, N+1):
        S += abs(d[i])

    if S % 2 != 0:
        print(-1)
        return

    if S == 0:
        print(0)
        return

    option1 = S // 2

    if S >= 2 and (S - 2) % 2 == 0:
        option2 = (S - 2) // 2
        min_option = min(option1, option2)
    else:
        min_option = option1

    print(min_option)

if __name__ == "__main__":
    main()
0