結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー ああいいああいい
提出日時 2023-08-05 18:20:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 886 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 112,408 KB
最終ジャッジ日時 2024-04-23 15:07:03
合計ジャッジ時間 5,325 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,360 KB
testcase_01 AC 37 ms
55,172 KB
testcase_02 AC 36 ms
54,464 KB
testcase_03 AC 39 ms
54,188 KB
testcase_04 AC 195 ms
77,792 KB
testcase_05 AC 218 ms
77,408 KB
testcase_06 AC 259 ms
78,616 KB
testcase_07 AC 177 ms
77,280 KB
testcase_08 AC 249 ms
77,800 KB
testcase_09 AC 268 ms
77,916 KB
testcase_10 AC 242 ms
78,380 KB
testcase_11 AC 217 ms
77,916 KB
testcase_12 AC 259 ms
78,520 KB
testcase_13 AC 246 ms
78,364 KB
testcase_14 AC 37 ms
53,668 KB
testcase_15 AC 37 ms
54,256 KB
testcase_16 AC 36 ms
54,092 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 95 ms
110,440 KB
testcase_20 AC 57 ms
71,568 KB
testcase_21 AC 63 ms
86,572 KB
testcase_22 AC 95 ms
112,312 KB
testcase_23 AC 93 ms
112,408 KB
testcase_24 AC 93 ms
102,812 KB
testcase_25 AC 66 ms
91,824 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 106 ms
98,104 KB
testcase_29 WA -
testcase_30 AC 86 ms
94,428 KB
testcase_31 AC 110 ms
103,040 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 84 ms
79,124 KB
権限があれば一括ダウンロードができます

ソースコード

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)
    if i != p:
        s.add(p)
    d[p].append(Gnum[i])
ans += len(s) - 1
#print(s)
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