Submission #68783222
Source Code Expand
# E12 debug
import sys
import pprint
import numpy as np
from numba import jit, boolean, int64, float64, typeof, types, typeof, objmode
def main():
from io import StringIO
execute(StringIO(sample), sys.stderr)
print("-- ^sample! --", file=sys.stderr)
execute(sys.stdin, sys.stdout)
if len(solve.nopython_signatures) != 1:
raise KeyboardInterrupt("!! Unexpected: wrong use of jit !!")
def execute(src, dst):
N, Q, = map(int, src.readline().split())
restnda = np.fromstring(src.read().strip(), dtype=np.int64, sep=' ')
ans = solve(N, Q, restnda)
print(*ans, sep="\n", file=dst)
sample = """\
5 12
3 2
2 2
3 2
1 2 5
1 3 4
3 4
3 5
1 4 5
1 1 3
3 1
2 2
3 1
"""
@jit(nopython=True, cache=True)
def solve(N, Q, restnda):
# print(N, Q)
Queries = []
i = 0
while i < len(restnda) :
if restnda[i] == 1:
Queries.append(restnda[i : i + 3])
i += 3
else:
Queries.append(restnda[i : i + 2])
i += 2
# [print(q) for q in Queries]
ans = []
uf1 = UnionFindSX_int64(N+1)
for query in Queries:
# print(uf1.blacks , end="")
if query[0] == 1:
ty, u, v = query
uf1.union(u, v)
# print("union", u, v, uf1.findroot(u), uf1.findroot(v), end="")
elif query[0] == 2:
ty, v = query
root = uf1.findroot(v)
s = uf1.blacks[root]
if v not in s:
s.add(v)
else:
s.discard(v)
elif query[0] == 3:
ty, v = query
root = uf1.findroot(v)
s = uf1.blacks[root]
if len(s) > 0 :
res = "Yes"
else:
res = "No"
ans.append(res)
# print(v,root , res, end="")
# print()
# print(uf.findroot(2))
# uf.union(1,2)
# uf.union(1,3)
# print(uf.findroot(3))
return ans
#
import numba
try:
from numba.experimental import jitclass
except ImportError:
from numba import jitclass
spec_UF = [
("_table_size", types.int64[:]),
("blacks", types.List(types.Set(types.int64))),
]
@jitclass(spec_UF)
class UnionFindSX_int64():
"""サイズを保持, サイズ基準で結合, 要素id:int64 """
"""各グループがsetを保持"""
def __init__(self, size):
self._table_size = np.full((size,), -1, dtype=np.int64)
self.blacks = [{-2, -3,} - {-2, -3,} for _i in range(size)]
def findroot(self, index):
parent1 = self._table_size[index]
if parent1 < 0:
return index
parent2 = self._table_size[parent1]
if parent2 < 0:
return parent1
start = index
depth = 1 # tocomp = depth - 1
while True:
depth += 1
parentnext = self._table_size[parent2]
if parentnext < 0:
break
parent2 = parentnext
root = parent2
update = start
for _i in range(depth -1):
parent = self._table_size[update]
self._table_size[update] = root
update = parent
return root
def union(self, x_index, y_index):
root_L = self.findroot(x_index)
root_S = self.findroot(y_index)
if root_L == root_S:
return False
size_L = -self._table_size[root_L]
size_S = -self._table_size[root_S]
if size_L < size_S:
(root_L, root_S,) = (root_S, root_L,)
self._table_size[root_S] = root_L # root を結合
# if size_L == size_S:
# self._table_size[root_L] -= 1
self._table_size[root_L] = -(size_S + size_L)
for b_s in self.blacks[root_S]:
self.blacks[root_L].add(b_s)
return True
def issame(self, x_index, y_index):
return self.findroot(x_index) == self.findroot(y_index)
def get_size(self, index):
root = self.findroot(index)
return -self._table_size[root]
main()
Submission Info
| Submission Time | |
|---|---|
| Task | E - Reachability Query |
| User | tariaki |
| Language | Python (CPython 3.11.4) |
| Score | 0 |
| Code Size | 4189 Byte |
| Status | TLE |
| Exec Time | 3327 ms |
| Memory | 303904 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 450 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt |
| All | sample_01.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt, test_70.txt, test_71.txt, test_72.txt, test_73.txt, test_74.txt, test_75.txt, test_76.txt, test_77.txt, test_78.txt, test_79.txt, test_80.txt, test_81.txt, test_82.txt, test_83.txt, test_84.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01.txt | AC | 393 ms | 144500 KiB |
| test_01.txt | AC | 386 ms | 144324 KiB |
| test_02.txt | AC | 386 ms | 144764 KiB |
| test_03.txt | AC | 617 ms | 231860 KiB |
| test_04.txt | AC | 619 ms | 231300 KiB |
| test_05.txt | AC | 490 ms | 194044 KiB |
| test_06.txt | AC | 584 ms | 217588 KiB |
| test_07.txt | AC | 538 ms | 204340 KiB |
| test_08.txt | TLE | 3320 ms | 202432 KiB |
| test_09.txt | TLE | 3320 ms | 195180 KiB |
| test_10.txt | TLE | 3320 ms | 195472 KiB |
| test_11.txt | TLE | 3320 ms | 194792 KiB |
| test_12.txt | TLE | 3320 ms | 194328 KiB |
| test_13.txt | AC | 507 ms | 193916 KiB |
| test_14.txt | AC | 521 ms | 201656 KiB |
| test_15.txt | AC | 528 ms | 201580 KiB |
| test_16.txt | TLE | 3320 ms | 195472 KiB |
| test_17.txt | TLE | 3320 ms | 195676 KiB |
| test_18.txt | TLE | 3320 ms | 194840 KiB |
| test_19.txt | TLE | 3320 ms | 195224 KiB |
| test_20.txt | AC | 526 ms | 201700 KiB |
| test_21.txt | TLE | 3324 ms | 267984 KiB |
| test_22.txt | AC | 695 ms | 285036 KiB |
| test_23.txt | AC | 718 ms | 292248 KiB |
| test_24.txt | TLE | 3324 ms | 269972 KiB |
| test_25.txt | TLE | 3327 ms | 267996 KiB |
| test_26.txt | TLE | 3324 ms | 268008 KiB |
| test_27.txt | TLE | 3323 ms | 268448 KiB |
| test_28.txt | TLE | 3324 ms | 267588 KiB |
| test_29.txt | AC | 718 ms | 292088 KiB |
| test_30.txt | AC | 722 ms | 288236 KiB |
| test_31.txt | AC | 741 ms | 303904 KiB |
| test_32.txt | AC | 725 ms | 292292 KiB |
| test_33.txt | AC | 713 ms | 284804 KiB |
| test_34.txt | AC | 699 ms | 280736 KiB |
| test_35.txt | AC | 750 ms | 292400 KiB |
| test_36.txt | AC | 699 ms | 280408 KiB |
| test_37.txt | TLE | 3325 ms | 279568 KiB |
| test_38.txt | AC | 659 ms | 269796 KiB |
| test_39.txt | AC | 706 ms | 288724 KiB |
| test_40.txt | TLE | 3323 ms | 267800 KiB |
| test_41.txt | TLE | 3324 ms | 268180 KiB |
| test_42.txt | TLE | 3324 ms | 268184 KiB |
| test_43.txt | TLE | 3324 ms | 268064 KiB |
| test_44.txt | TLE | 3324 ms | 267988 KiB |
| test_45.txt | TLE | 3325 ms | 279248 KiB |
| test_46.txt | AC | 706 ms | 281676 KiB |
| test_47.txt | AC | 704 ms | 282728 KiB |
| test_48.txt | TLE | 3324 ms | 272644 KiB |
| test_49.txt | TLE | 3324 ms | 269892 KiB |
| test_50.txt | TLE | 3324 ms | 271820 KiB |
| test_51.txt | TLE | 3320 ms | 267508 KiB |
| test_52.txt | TLE | 3325 ms | 285580 KiB |
| test_53.txt | TLE | 3324 ms | 270272 KiB |
| test_54.txt | AC | 703 ms | 288668 KiB |
| test_55.txt | AC | 725 ms | 298844 KiB |
| test_56.txt | TLE | 3324 ms | 268444 KiB |
| test_57.txt | TLE | 3324 ms | 267444 KiB |
| test_58.txt | TLE | 3324 ms | 267732 KiB |
| test_59.txt | TLE | 3324 ms | 271412 KiB |
| test_60.txt | TLE | 3324 ms | 268400 KiB |
| test_61.txt | AC | 683 ms | 281368 KiB |
| test_62.txt | AC | 724 ms | 295864 KiB |
| test_63.txt | AC | 689 ms | 283224 KiB |
| test_64.txt | AC | 711 ms | 290404 KiB |
| test_65.txt | AC | 689 ms | 286400 KiB |
| test_66.txt | AC | 734 ms | 296104 KiB |
| test_67.txt | AC | 744 ms | 302120 KiB |
| test_68.txt | AC | 732 ms | 295572 KiB |
| test_69.txt | TLE | 3320 ms | 206804 KiB |
| test_70.txt | AC | 590 ms | 241132 KiB |
| test_71.txt | AC | 578 ms | 227464 KiB |
| test_72.txt | TLE | 3323 ms | 265832 KiB |
| test_73.txt | TLE | 3322 ms | 237188 KiB |
| test_74.txt | TLE | 3323 ms | 249388 KiB |
| test_75.txt | TLE | 3322 ms | 232448 KiB |
| test_76.txt | AC | 667 ms | 254440 KiB |
| test_77.txt | AC | 641 ms | 270612 KiB |
| test_78.txt | AC | 674 ms | 271940 KiB |
| test_79.txt | AC | 705 ms | 292004 KiB |
| test_80.txt | TLE | 3324 ms | 269904 KiB |
| test_81.txt | TLE | 3324 ms | 270724 KiB |
| test_82.txt | TLE | 3324 ms | 272400 KiB |
| test_83.txt | TLE | 3324 ms | 270768 KiB |
| test_84.txt | TLE | 3324 ms | 274060 KiB |