Submission #17535199


Source Code Expand

cycode = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/ac-library
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/dsu>" namespace "atcoder":
    cdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()
cdef class DSU:
    cdef dsu *_thisptr
    def __cinit__(self, int n):
        self._thisptr = new dsu(n)
    cpdef int merge(self, int a, int b):
        return self._thisptr.merge(a, b)
    cpdef bool same(self, int a, int b):
        return self._thisptr.same(a, b)
    cpdef int leader(self, int a):
        return self._thisptr.leader(a)
    cpdef int size(self, int a):
        return self._thisptr.size(a)
    cpdef vector[vector[int]] groups(self):
        return self._thisptr.groups()
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('dsu.pyx', 'w').write(cycode)
    os.system('cythonize -i -3 dsu.pyx')
from dsu import DSU
n, q = map(int, input().split())
dsu = DSU(n)
res = []
for i in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        dsu.merge(u, v)
    else:
        if dsu.same(u, v):
            res.append(1)
        else:
            res.append(0)
print('\n'.join(map(str, res)))

Submission Info

Submission Time
Task A - Disjoint Set Union
User c_r_5
Language Python (3.8.2)
Score 100
Code Size 1324 Byte
Status AC
Exec Time 424 ms
Memory 18092 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 11
Set Name Test Cases
Sample example_00
All example_00, random_00, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09
Case Name Status Exec Time Memory
example_00 AC 34 ms 10008 KiB
random_00 AC 325 ms 16348 KiB
random_01 AC 329 ms 16432 KiB
random_02 AC 269 ms 14760 KiB
random_03 AC 80 ms 11360 KiB
random_04 AC 228 ms 13712 KiB
random_05 AC 312 ms 15556 KiB
random_06 AC 254 ms 14692 KiB
random_07 AC 54 ms 10524 KiB
random_08 AC 127 ms 11760 KiB
random_09 AC 424 ms 18092 KiB