結果

問題 No.2290 UnUnion Find
ユーザー buey_tbuey_t
提出日時 2023-05-08 13:08:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,665 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 104,364 KB
最終ジャッジ日時 2024-11-25 06:15:44
合計ジャッジ時間 19,808 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 122 ms
89,344 KB
testcase_02 AC 188 ms
90,368 KB
testcase_03 AC 244 ms
95,976 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 250 ms
95,856 KB
testcase_13 AC 250 ms
97,996 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 252 ms
95,488 KB
testcase_18 AC 258 ms
95,544 KB
testcase_19 AC 461 ms
96,988 KB
testcase_20 AC 393 ms
95,104 KB
testcase_21 WA -
testcase_22 AC 407 ms
94,848 KB
testcase_23 WA -
testcase_24 AC 418 ms
104,364 KB
testcase_25 AC 335 ms
92,336 KB
testcase_26 AC 303 ms
93,844 KB
testcase_27 AC 365 ms
93,632 KB
testcase_28 AC 414 ms
95,480 KB
testcase_29 AC 420 ms
96,584 KB
testcase_30 WA -
testcase_31 AC 426 ms
100,452 KB
testcase_32 AC 356 ms
92,756 KB
testcase_33 WA -
testcase_34 AC 332 ms
93,896 KB
testcase_35 AC 399 ms
94,696 KB
testcase_36 WA -
testcase_37 AC 411 ms
97,768 KB
testcase_38 AC 363 ms
92,824 KB
testcase_39 AC 354 ms
93,084 KB
testcase_40 AC 374 ms
93,988 KB
testcase_41 AC 371 ms
93,684 KB
testcase_42 AC 445 ms
98,348 KB
testcase_43 AC 445 ms
99,708 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 249 ms
95,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from random import randrange
from collections import deque,Counter,defaultdict
from itertools import permutations,combinations
from decimal import Decimal,ROUND_HALF_UP
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import lru_cache, reduce
#@lru_cache(maxsize=None)
from operator import add,sub,mul,xor,and_,or_,itemgetter
import sys
input = sys.stdin.readline
# .rstrip()
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353
#DecimalPython
#Python!!!!!!!!!!!!!!!!!!!!!!!!!!
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
#
self.edge = [0]*n
self.count = 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 self.parents[x] > self.parents[y]:
x, y = y, x
self.edge[x] += 1
if x == y:
return
self.count -= 1
self.parents[x] += self.parents[y]
self.edge[x] += self.edge[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 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,Q = map(int, input().split())
uf = UnionFind(N+1)
l = 1
r = N
for i in range(Q):
tmp = list(map(int, input().split()))
if tmp[0] == 1:
t,u,v = tmp
uf.union(u,v)
while uf.find(l) != l:
l += 1
while uf.find(r) != r:
r -= 1
else:
t,v = tmp
if l == r:
print(-1)
else:
if r == v:
print(l)
else:
print(r)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0