結果
問題 | No.2403 "Eight" Bridges of Königsberg |
ユーザー | Mottchan |
提出日時 | 2023-08-05 10:08:43 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,749 bytes |
コンパイル時間 | 282 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 123,460 KB |
最終ジャッジ日時 | 2024-10-15 07:30:44 |
合計ジャッジ時間 | 8,275 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
55,168 KB |
testcase_01 | AC | 43 ms
54,808 KB |
testcase_02 | AC | 43 ms
56,044 KB |
testcase_03 | AC | 44 ms
54,800 KB |
testcase_04 | AC | 286 ms
89,380 KB |
testcase_05 | AC | 485 ms
105,528 KB |
testcase_06 | AC | 549 ms
106,156 KB |
testcase_07 | AC | 332 ms
93,216 KB |
testcase_08 | AC | 395 ms
97,404 KB |
testcase_09 | AC | 554 ms
110,976 KB |
testcase_10 | AC | 440 ms
106,288 KB |
testcase_11 | AC | 422 ms
100,724 KB |
testcase_12 | AC | 517 ms
109,956 KB |
testcase_13 | AC | 433 ms
100,540 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 112 ms
108,828 KB |
testcase_20 | AC | 60 ms
71,776 KB |
testcase_21 | AC | 72 ms
88,268 KB |
testcase_22 | AC | 108 ms
105,432 KB |
testcase_23 | AC | 105 ms
105,792 KB |
testcase_24 | AC | 109 ms
99,812 KB |
testcase_25 | AC | 95 ms
105,264 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 134 ms
101,380 KB |
testcase_29 | WA | - |
testcase_30 | AC | 101 ms
93,636 KB |
testcase_31 | AC | 167 ms
123,368 KB |
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) e.append([a,b]) uf.union(a,b) dout[b]+=1 din[a]+=1 ans=0 cnt=-1 cnt2=0 for i,l in uf.group().items(): if len(l) == 1: continue cnt2+=1 cnt+=1 for j in l: ans+=abs(din[j] - dout[j]) print(ans//2-(1*cnt2)+cnt)