結果
| 問題 |
No.2403 "Eight" Bridges of Königsberg
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:41:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 867 bytes |
| コンパイル時間 | 263 ms |
| コンパイル使用メモリ | 82,508 KB |
| 実行使用メモリ | 109,912 KB |
| 最終ジャッジ日時 | 2025-06-12 19:41:04 |
| 合計ジャッジ時間 | 3,561 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 10 |
ソースコード
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()
gew1fw