結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー FromBooskaFromBooska
提出日時 2023-08-05 11:45:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 947 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 87,024 KB
最終ジャッジ日時 2024-04-23 08:55:25
合計ジャッジ時間 4,404 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,872 KB
testcase_01 AC 33 ms
52,276 KB
testcase_02 AC 33 ms
53,572 KB
testcase_03 AC 35 ms
53,020 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 52 ms
71,376 KB
testcase_20 AC 48 ms
64,288 KB
testcase_21 AC 48 ms
67,028 KB
testcase_22 AC 50 ms
71,320 KB
testcase_23 AC 48 ms
71,308 KB
testcase_24 AC 56 ms
70,084 KB
testcase_25 AC 45 ms
66,824 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 78 ms
84,700 KB
testcase_29 WA -
testcase_30 AC 51 ms
67,260 KB
testcase_31 AC 83 ms
86,700 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 頂点すべてに達するのではなく辺すべてに達する(使う)
# まず多重辺は打ち消しあう分を消そう、いらないから
# 自己ループも消そう、いらないから
# それから、辺が何本の線になっているか
# degreeをinward, outwardで数えるか
# outward-inwardでプラスをすべて数えればそれが線の数
# 答えはそこから1を引けばいいか、やってみよう

N, M = map(int, input().split())
edges = [set() for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    if u == v:
        continue
    if u in edges[v]:
        edges[v].discard(u)
    else:
        edges[u].add(v)

inward = [0]*(N+1)
outward = [0]*(N+1)

for i in range(1, N+1):
    outward[i] += len(edges[i])
    for nxt in edges[i]:
        inward[nxt] += 1
        
count = 0
for i in range(1, N+1):
    count += max(0, outward[i]-inward[i])
ans = count-1
print(ans)








0