結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー LyricalMaestro
提出日時 2025-07-13 00:54:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2025-07-13 00:54:08
合計ジャッジ時間 5,390 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2403


def main():
    N, M = map(int, input().split())
    in_degrees = [0] * N
    out_degrees = [0] * N

    for _ in range(M):
        u, v = map(int, input().split())
        in_degrees[u - 1] += 1
        out_degrees[v - 1] += 1
    
    in_degree_total = 0
    out_degree_total = 0
    for i in range(N):
        if in_degrees[i] > out_degrees[i]:
            in_degree_total += in_degrees[i] - out_degrees[i]
        elif in_degrees[i] < out_degrees[i]:
            out_degree_total += out_degrees[i] - in_degrees[i]
    
    if in_degree_total != out_degree_total:
        print(-1)
        return
    
    a = max(0, in_degree_total - 1)
    print(a)







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