結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー gr1msl3ygr1msl3y
提出日時 2023-08-13 13:31:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 796 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 90,324 KB
最終ジャッジ日時 2024-05-01 06:46:06
合計ジャッジ時間 5,441 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,352 KB
testcase_01 AC 32 ms
52,196 KB
testcase_02 AC 32 ms
52,744 KB
testcase_03 AC 35 ms
52,592 KB
testcase_04 AC 131 ms
80,280 KB
testcase_05 AC 197 ms
85,192 KB
testcase_06 AC 226 ms
86,896 KB
testcase_07 AC 150 ms
81,656 KB
testcase_08 AC 166 ms
82,500 KB
testcase_09 AC 223 ms
85,980 KB
testcase_10 AC 211 ms
85,600 KB
testcase_11 AC 177 ms
83,956 KB
testcase_12 AC 220 ms
85,044 KB
testcase_13 AC 166 ms
82,760 KB
testcase_14 AC 32 ms
53,296 KB
testcase_15 AC 33 ms
53,636 KB
testcase_16 AC 32 ms
53,148 KB
testcase_17 WA -
testcase_18 AC 33 ms
52,688 KB
testcase_19 AC 105 ms
89,356 KB
testcase_20 AC 66 ms
78,304 KB
testcase_21 AC 82 ms
82,616 KB
testcase_22 AC 99 ms
87,944 KB
testcase_23 AC 96 ms
87,064 KB
testcase_24 AC 105 ms
85,048 KB
testcase_25 AC 84 ms
84,508 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 147 ms
86,480 KB
testcase_29 WA -
testcase_30 AC 96 ms
81,292 KB
testcase_31 AC 143 ms
89,888 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 123 ms
78,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
g0 = [[] for _ in range(N+1)]
g1 = [[] for _ in range(N+1)]
for _ in range(K):
    a, b = map(int, input().split())
    g0[a].append(b)
    g1[b].append(a)

ans = 0
seen = [0]*(N+1)
ct0 = ct1 = 0
for i in range(1, N+1):
    if seen[i]:
        continue
    seen[i] = 1
    task = [i]
    for v in task:
        for u in g0[v]:
            if seen[u]:
                continue
            seen[u] = 1
            task.append(u)
        for u in g1[v]:
            if seen[u]:
                continue
            seen[u] = 1
            task.append(u)
    res = sum(abs(len(g0[v])-len(g1[v])) for v in task)//2
    if len(task) == 1:
        continue
    if res:
        ct1 += 1
        ans += res-1
    else:
        ct0 += 1
ans += max(0, ct0+ct1-1)
print(ans)
0