結果
問題 | No.1293 2種類の道路 |
ユーザー |
![]() |
提出日時 | 2020-11-21 03:55:15 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 993 ms / 2,000 ms |
コード長 | 857 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 31,456 KB |
最終ジャッジ日時 | 2024-07-23 14:23:09 |
合計ジャッジ時間 | 14,003 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
class UnionFind:def __init__(self, n):self.parent = list(range(n))self.size = [1] * ndef find(self, n):if self.parent[n] == n:return nself.parent[n] = self.find(self.parent[n])return self.parent[n]def merge(self, m, n):m = self.find(m)n = self.find(n)if m == n:returnif m > n:m, n = n, mself.parent[m] = nself.size[n] += self.size[m]n, d, w = map(int, input().split())x = UnionFind(n)y = UnionFind(n)for i in range(d):a, b = map(int, input().split())x.merge(a - 1, b - 1)for i in range(w):a, b = map(int, input().split())y.merge(a - 1, b - 1)s = set()for i in range(n):s.add((x.find(i), y.find(i)))ans = -nfor a, b in s:ans += x.size[a] * y.size[b]print(ans)