結果
問題 | No.2403 "Eight" Bridges of Königsberg |
ユーザー | Mottchan |
提出日時 | 2023-08-04 23:14:09 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,881 bytes |
コンパイル時間 | 492 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 123,648 KB |
最終ジャッジ日時 | 2024-10-14 21:27:01 |
合計ジャッジ時間 | 8,337 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
53,888 KB |
testcase_01 | AC | 44 ms
54,400 KB |
testcase_02 | AC | 44 ms
54,144 KB |
testcase_03 | AC | 44 ms
54,016 KB |
testcase_04 | AC | 290 ms
90,496 KB |
testcase_05 | AC | 503 ms
107,972 KB |
testcase_06 | AC | 592 ms
114,032 KB |
testcase_07 | AC | 343 ms
94,776 KB |
testcase_08 | AC | 428 ms
99,316 KB |
testcase_09 | AC | 549 ms
114,780 KB |
testcase_10 | AC | 488 ms
110,816 KB |
testcase_11 | AC | 462 ms
103,424 KB |
testcase_12 | AC | 561 ms
114,332 KB |
testcase_13 | AC | 463 ms
102,988 KB |
testcase_14 | AC | 42 ms
54,016 KB |
testcase_15 | AC | 44 ms
53,632 KB |
testcase_16 | AC | 44 ms
53,632 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 | - |
ソースコード
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def group(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return ''.join(f'{r}: {m}' for r, m in self.group().items()) n,m = map(int,input().split()) uf = UnionFind(n) graph = [[] for i in range(n+1)] e=[] dout = defaultdict(int) din = defaultdict(int) for i in range(m): a,b = map(int,input().split()) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) e.append([a,b]) uf.union(a,b) dout[b]+=1 din[a]+=1 cnt1=[] cnt2=-1 for i,l in uf.group().items(): if len(l)==1:continue cnt2+=1 for j in l: if dout[j] == din[j]: continue else: cnt1.append(abs(dout[j] - din[j])) s=sum(cnt1) if s==0: print(0+cnt2) else: print(sum(cnt1)//2-1+cnt2)