結果
問題 | No.2403 "Eight" Bridges of Königsberg |
ユーザー | ntuda |
提出日時 | 2023-08-05 12:46:43 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,069 bytes |
コンパイル時間 | 248 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 98,720 KB |
最終ジャッジ日時 | 2024-04-23 09:59:36 |
合計ジャッジ時間 | 5,203 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,888 KB |
testcase_01 | AC | 36 ms
53,476 KB |
testcase_02 | AC | 35 ms
52,540 KB |
testcase_03 | AC | 33 ms
52,864 KB |
testcase_04 | AC | 183 ms
86,656 KB |
testcase_05 | AC | 258 ms
95,716 KB |
testcase_06 | AC | 293 ms
97,540 KB |
testcase_07 | AC | 204 ms
89,700 KB |
testcase_08 | AC | 227 ms
91,680 KB |
testcase_09 | AC | 285 ms
98,260 KB |
testcase_10 | AC | 268 ms
97,512 KB |
testcase_11 | AC | 233 ms
92,836 KB |
testcase_12 | AC | 288 ms
98,720 KB |
testcase_13 | AC | 222 ms
91,744 KB |
testcase_14 | AC | 34 ms
54,068 KB |
testcase_15 | WA | - |
testcase_16 | AC | 32 ms
53,484 KB |
testcase_17 | WA | - |
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 | - |
ソースコード
''' YC2403 "Eight" Bridges of Königsberg 有向グラフに辺を追加して、各辺を1回ずつ通るようにする 最小追加変数は幾つか? 必要な条件 ・連結であること ・出次数と入次数がすべて等しいか、差が+1の頂点と-1の頂点が1個ずつある ''' def root(x): if P[x] < 0: return x P[x] = root(P[x]) # 経路圧縮 return P[x] def unite(x,y): x = root(x) y = root(y) if x == y: return if x > y: x,y = y,x P[x] += P[y] P[y] = x def same(x,y): return root(x) == root(y) def size(x): x = root(x) return -P[x] def group_count(): S = set() for i in range(N): if size(i) > 1: S.add(root(i)) return len(S) N,M = map(int,input().split()) P = [-1] * (N + 1) UV = [list(map(int,input().split())) for _ in range(M)] F = [[0,0] for _ in range(N+1)] for u,v in UV: F[u][0] += 1 F[v][1] += 1 unite(u,v) tmp = group_count() tmp2 = 0 for i in range(N+1): tmp2 += abs(F[i][0] - F[i][1]) tmp2 //= 2 print(tmp2 - 1 + tmp - 1)