結果
問題 | No.2403 "Eight" Bridges of Königsberg |
ユーザー | Mottchan |
提出日時 | 2023-08-04 23:28:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,983 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 82,344 KB |
実行使用メモリ | 123,520 KB |
最終ジャッジ日時 | 2024-10-14 21:43:31 |
合計ジャッジ時間 | 9,532 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
54,016 KB |
testcase_01 | AC | 48 ms
54,272 KB |
testcase_02 | AC | 46 ms
54,144 KB |
testcase_03 | AC | 50 ms
54,272 KB |
testcase_04 | AC | 295 ms
90,752 KB |
testcase_05 | AC | 527 ms
107,836 KB |
testcase_06 | AC | 620 ms
113,984 KB |
testcase_07 | AC | 345 ms
95,148 KB |
testcase_08 | AC | 441 ms
99,488 KB |
testcase_09 | AC | 596 ms
115,544 KB |
testcase_10 | AC | 505 ms
110,792 KB |
testcase_11 | AC | 469 ms
103,776 KB |
testcase_12 | AC | 579 ms
114,588 KB |
testcase_13 | AC | 474 ms
103,116 KB |
testcase_14 | AC | 46 ms
54,144 KB |
testcase_15 | AC | 46 ms
55,196 KB |
testcase_16 | AC | 44 ms
55,308 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 119 ms
108,748 KB |
testcase_20 | AC | 68 ms
71,552 KB |
testcase_21 | AC | 84 ms
87,808 KB |
testcase_22 | AC | 122 ms
105,696 KB |
testcase_23 | AC | 115 ms
105,728 KB |
testcase_24 | AC | 123 ms
100,264 KB |
testcase_25 | AC | 109 ms
104,832 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 173 ms
113,792 KB |
testcase_29 | WA | - |
testcase_30 | AC | 114 ms
93,952 KB |
testcase_31 | AC | 196 ms
123,520 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 143 ms
80,256 KB |
ソースコード
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=defaultdict(list) 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[i].append(abs(dout[j] - din[j])) ans=0 for i,l in cnt1.items(): s=sum(l) if s ==0: continue else: ans+=s//2-1 if ans==0: print(0+cnt2) else: print(ans+cnt2)