結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー ああいいああいい
提出日時 2023-08-05 18:13:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 852 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 82,108 KB
実行使用メモリ 126,864 KB
最終ジャッジ日時 2024-04-23 15:01:21
合計ジャッジ時間 6,117 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,388 KB
testcase_01 AC 41 ms
54,304 KB
testcase_02 AC 41 ms
54,776 KB
testcase_03 WA -
testcase_04 AC 229 ms
77,776 KB
testcase_05 AC 250 ms
77,464 KB
testcase_06 AC 302 ms
78,524 KB
testcase_07 AC 207 ms
77,100 KB
testcase_08 AC 246 ms
77,580 KB
testcase_09 AC 304 ms
77,728 KB
testcase_10 AC 273 ms
78,536 KB
testcase_11 AC 244 ms
77,988 KB
testcase_12 AC 299 ms
78,344 KB
testcase_13 AC 282 ms
78,248 KB
testcase_14 AC 42 ms
54,808 KB
testcase_15 AC 42 ms
56,044 KB
testcase_16 WA -
testcase_17 AC 42 ms
55,420 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 8)


N,M = map(int,input().split())
Gnum = [0] * (N + 1)

parent = list(range(N + 1))
def find(i):
    if parent[i] == i:return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    parent[i] = J
    parent[I] = J
    return True

for _ in range(M):
    u,v = map(int,input().split())
    Gnum[u] -= 1
    Gnum[v] += 1
    unite(u,v)

ans = 0
from collections import defaultdict
d = defaultdict(list)
s = set()
for i in range(1,N + 1):
    p = find(i)
    s.add(p)
    d[p].append(Gnum[i])
ans += len(s) - 1
for l in d.values():
    tmp = 0
    f = 0
    for u in l:
        if u > 0:
            if f == 0:
                tmp += u - 1
                f = 1
            else:
                tmp += u
    ans += tmp
print(ans)
    
0