結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー Mottchan
提出日時 2023-08-04 22:38:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 667 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 117,248 KB
最終ジャッジ日時 2024-10-14 20:41:33
合計ジャッジ時間 4,956 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

dout = defaultdict(int)
din = defaultdict(int)

n,m = map(int,input().split())
for i in range(m):
    a,b = map(int,input().split())
    dout[b-1]+=1
    din[a-1]+=1

cnt1=0
cnt2=0
for i in range(n):
    if dout[i] == din[i]:
        continue
    elif dout[i] > din[i]:
        cnt1+= dout[i] - din[i]
    else:
        cnt2+= din[i] - dout[i]

if cnt1 != cnt2:
    print(-1)
elif cnt1+cnt2 == 0:
    print(0)
else:
    print((cnt1+cnt2)//2-1)
0