結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー MottchanMottchan
提出日時 2023-08-04 22:38:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 667 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 118,244 KB
最終ジャッジ日時 2024-04-22 20:57:56
合計ジャッジ時間 3,983 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,352 KB
testcase_01 AC 40 ms
55,480 KB
testcase_02 AC 37 ms
55,292 KB
testcase_03 AC 37 ms
55,672 KB
testcase_04 AC 93 ms
76,976 KB
testcase_05 AC 131 ms
79,680 KB
testcase_06 AC 126 ms
80,300 KB
testcase_07 AC 91 ms
77,512 KB
testcase_08 AC 104 ms
79,592 KB
testcase_09 AC 129 ms
80,376 KB
testcase_10 AC 117 ms
78,868 KB
testcase_11 AC 111 ms
79,360 KB
testcase_12 AC 128 ms
79,624 KB
testcase_13 AC 109 ms
79,404 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 37 ms
55,920 KB
testcase_19 AC 94 ms
118,244 KB
testcase_20 AC 53 ms
72,996 KB
testcase_21 AC 77 ms
91,316 KB
testcase_22 AC 90 ms
112,608 KB
testcase_23 AC 86 ms
106,352 KB
testcase_24 AC 81 ms
102,668 KB
testcase_25 AC 73 ms
97,148 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 86 ms
105,812 KB
testcase_29 WA -
testcase_30 AC 72 ms
86,036 KB
testcase_31 AC 93 ms
115,280 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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