結果
問題 | No.1390 Get together |
ユーザー | itsy68 |
提出日時 | 2022-04-15 06:08:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 304 ms / 2,000 ms |
コード長 | 2,019 bytes |
コンパイル時間 | 480 ms |
コンパイル使用メモリ | 82,284 KB |
実行使用メモリ | 96,784 KB |
最終ジャッジ日時 | 2024-06-06 20:55:51 |
合計ジャッジ時間 | 8,396 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
62,720 KB |
testcase_01 | AC | 45 ms
63,104 KB |
testcase_02 | AC | 45 ms
62,976 KB |
testcase_03 | AC | 78 ms
77,644 KB |
testcase_04 | AC | 76 ms
77,312 KB |
testcase_05 | AC | 88 ms
77,440 KB |
testcase_06 | AC | 76 ms
77,408 KB |
testcase_07 | AC | 84 ms
77,572 KB |
testcase_08 | AC | 75 ms
77,200 KB |
testcase_09 | AC | 79 ms
77,440 KB |
testcase_10 | AC | 47 ms
62,976 KB |
testcase_11 | AC | 46 ms
62,848 KB |
testcase_12 | AC | 45 ms
62,720 KB |
testcase_13 | AC | 47 ms
63,232 KB |
testcase_14 | AC | 47 ms
62,720 KB |
testcase_15 | AC | 47 ms
62,848 KB |
testcase_16 | AC | 135 ms
90,920 KB |
testcase_17 | AC | 209 ms
94,468 KB |
testcase_18 | AC | 134 ms
91,672 KB |
testcase_19 | AC | 264 ms
96,416 KB |
testcase_20 | AC | 276 ms
95,940 KB |
testcase_21 | AC | 304 ms
96,784 KB |
testcase_22 | AC | 213 ms
96,256 KB |
testcase_23 | AC | 221 ms
95,568 KB |
testcase_24 | AC | 223 ms
96,112 KB |
testcase_25 | AC | 285 ms
96,768 KB |
testcase_26 | AC | 261 ms
96,068 KB |
testcase_27 | AC | 275 ms
96,148 KB |
testcase_28 | AC | 265 ms
96,636 KB |
testcase_29 | AC | 273 ms
96,548 KB |
testcase_30 | AC | 300 ms
96,008 KB |
testcase_31 | AC | 268 ms
96,576 KB |
ソースコード
# import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') import sys from itertools import combinations, permutations, product, accumulate, groupby from collections import defaultdict, deque, Counter from functools import reduce from operator import add, mul import heapq import bisect import math import copy # sys.setrecursionlimit(10 ** 7) input = lambda: sys.stdin.readline().rstrip() INF = float("inf") MOD = 10 ** 9 + 7 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 all_group_members(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 '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) N, M = map(int, input().split()) L = [[] for i in range(N+1)] for i in range(N): b, c = map(int, input().split()) L[c].append(b) uf = UnionFind(M + 1) cnt = 0 for l in L: for c in l: if not uf.same(l[0], c): uf.union(l[0], c) cnt += 1 print(cnt)