結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー bug maker / ばぐめいかー@Python学習者bug maker / ばぐめいかー@Python学習者
提出日時 2023-08-04 23:59:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 566 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 48,256 KB
最終ジャッジ日時 2024-04-22 22:22:20
合計ジャッジ時間 5,042 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,624 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 30 ms
10,624 KB
testcase_04 AC 152 ms
27,264 KB
testcase_05 AC 307 ms
42,752 KB
testcase_06 AC 301 ms
44,544 KB
testcase_07 AC 198 ms
31,872 KB
testcase_08 AC 225 ms
34,944 KB
testcase_09 AC 345 ms
47,488 KB
testcase_10 AC 358 ms
47,232 KB
testcase_11 AC 242 ms
37,632 KB
testcase_12 AC 341 ms
48,256 KB
testcase_13 AC 227 ms
35,328 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 51 ms
14,464 KB
testcase_20 AC 35 ms
11,392 KB
testcase_21 AC 40 ms
12,544 KB
testcase_22 AC 47 ms
14,208 KB
testcase_23 AC 48 ms
14,080 KB
testcase_24 AC 44 ms
13,440 KB
testcase_25 AC 44 ms
13,056 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 48 ms
13,824 KB
testcase_29 WA -
testcase_30 AC 39 ms
12,288 KB
testcase_31 AC 51 ms
14,592 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    
    l = [list(map(int, input().split())) for l in range(M)]

    lout = [0] * (N+1)
    lin = [0] * (N+1)
    lans = [0] * (N+1)

    for i in range(M):
        lout[l[i][0]] += 1
        lin[l[i][1]] += 1

    for i in range(1, N + 1):
        lans[i] = lout[i] - lin[i]

    lpos = sum([i for i in lans if i > 0])
    lneg = sum([i for i in lans if i < 0])

    if lpos == -lneg:
        print(lpos - 1)
    else:
        print(-1)

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