s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s785404664 | p02536 | u956318161 | 1601347963 | Python | Python (3.8.2) | py | Runtime Error | 207 | 12900 | 914 | 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 = ... |
s402772266 | p02536 | u043048943 | 1601347928 | Python | PyPy3 (7.3.0) | py | Runtime Error | 265 | 75204 | 1337 | 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 = ... |
s738106742 | p02536 | u956318161 | 1601346717 | Python | Python (3.8.2) | py | Runtime Error | 213 | 10448 | 949 | 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 = ... |
s074818380 | p02536 | u097700948 | 1601338245 | Python | Python (3.8.2) | py | Runtime Error | 295 | 18196 | 387 | N, M = map(int, input().split())
parents = [i for i in range(N+1)]
def find(x):
if x == parents[x]:
return x
else:
x = find(parents[x])
return x
def same(x, y):
if x==y:
pass
else:
parents[x] = y
for _ in range(M):
A, B = map(int, input().split())
x... |
s542290645 | p02536 | u097700948 | 1601338070 | Python | Python (3.8.2) | py | Runtime Error | 28 | 9068 | 357 | N, M = map(int, input().split())
def find(x):
if x == parents[x]:
return x
else:
x = find(parents[x])
return x
def same(x, y):
if x==y:
pass
else:
parents[x] = y
for _ in range(M):
A, B = map(int, input().split())
x, y = find(A), find(B)
same(x,... |
s797076963 | p02536 | u329319441 | 1601323546 | Python | Python (3.8.2) | py | Runtime Error | 669 | 597628 | 718 | import sys
sys.setrecursionlimit(int(1e9))
class uft:
def __init__(self, N):
self.__N = N
self.__arr = [-1] * (N + 1)
def fp(self, x):
if self.__arr[x] < 0:
return x
else:
self.__arr[x] = self.fp(self.__arr[x])
return self.__arr[x]
def add(self, x, y):
if x == y:
ret... |
s579331142 | p02536 | u329319441 | 1601322948 | Python | Python (3.8.2) | py | Runtime Error | 660 | 597680 | 714 | import sys
sys.setrecursionlimit(int(1e9))
class uft:
def __init__(self, N):
self.__N = N
self.__arr = [-1] * (N + 1)
def fp(self, x):
if self.__arr[x] < 0:
return x
else:
self.__arr[x] = self.fp(self.__arr[x])
return self.__arr[x]
def add(self, x, y):
if x == y:
ret... |
s872426833 | p02536 | u035453792 | 1601319057 | Python | Python (3.8.2) | py | Runtime Error | 150 | 10796 | 519 | import collections
n,m = map(int,input().split())
ans = [0]*n
ans[0]=1
for _ in range(m):
a,b = map(int,input().split())
if ans[a]==0 and ans[b]==0:
if a<b:
ans[a]=a
ans[b]=a
else:
ans[a]=b
ans[b]=b
elif ans[a]!=0 and ans[b]!=0:
if ans[... |
s813420999 | p02536 | u989306199 | 1601312475 | Python | Python (3.8.2) | py | Runtime Error | 188 | 12884 | 1381 | 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 = ... |
s888962650 | p02536 | u989306199 | 1601312097 | Python | PyPy3 (7.3.0) | py | Runtime Error | 281 | 75004 | 1381 | 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 = ... |
s548695202 | p02536 | u999799597 | 1601307107 | Python | Python (3.8.2) | py | Runtime Error | 312 | 10732 | 902 | # https://atcoder.jp/contests/atc001/tasks/unionfind_a
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 s... |
s510391774 | p02536 | u200916944 | 1601306159 | Python | PyPy3 (7.3.0) | py | Runtime Error | 216 | 104860 | 699 | (N,M),*AB=[list(map(int, x.split())) for x in open(0).readlines() if len(x)>1]
class UnionFind:
def __init__(self, n):
self.par=[i for i in range(n)]
def root(self, x):
if self.par[x] == x:
return x
return self.par[x] == self.root(self.par[x])
def union(self, x, y):
... |
s265911914 | p02536 | u329319441 | 1601304138 | Python | Python (3.8.2) | py | Runtime Error | 639 | 597836 | 702 | import sys
sys.setrecursionlimit(int(1e9))
N, M = map(int, input().split())
class uft:
def __init__(self, N):
self.__N = N
self.__arr = [-1] * (N + 1)
def fp(self, x):
if self.__arr[x] < 0:
return x
else:
self.__arr[x] = self.fp(self.__arr[x])
return self.__arr[x]
def add(self, x... |
s130458910 | p02536 | u329319441 | 1601303128 | Python | Python (3.8.2) | py | Runtime Error | 158 | 11376 | 659 | N, M = map(int, input().split())
class uft:
def __init__(self, N):
self.__N = N
self.__arr = [-1] * (N + 1)
def fp(self, x):
if self.__arr[x] < 0:
return x
else:
self.__arr[x] = self.fp(self.__arr[x])
return self.__arr[x]
def add(self, x, y):
if x > y:
x, y = y, x
i... |
s899072385 | p02536 | u329319441 | 1601302908 | Python | Python (3.8.2) | py | Runtime Error | 155 | 11584 | 629 | N, M = map(int, input().split())
class uft:
def __init__(self, N):
self.__N = N
self.__arr = [-1] * (N + 1)
def fp(self, x):
if self.__arr[x] < 0:
return x
else:
self.__arr[x] = self.fp(self.__arr[x])
return self.__arr[x]
def add(self, x, y):
if x > y:
x, y = y, x
p... |
s769741906 | p02536 | u200916944 | 1601301621 | Python | PyPy3 (7.3.0) | py | Runtime Error | 162 | 94268 | 293 | (N,M),*AB=[list(map(int, x.split())) for x in open(0).readlines() if len(x)>1]
d={}
g=0
for a,b in AB:
if a in d:
d[b] = d[a]
elif b in d:
b[a] = d[b]
else:
g += 1
d[a] = d[b] = g
for i in range(1,N+1):
if not i in d:
g += 1
print(g - 1) |
s831506898 | p02536 | u329319441 | 1601297721 | Python | Python (3.8.2) | py | Runtime Error | 156 | 11504 | 627 | N, M = map(int, input().split())
class uft:
def __init__(self, N):
self.__N = N
self.__arr = [-1] * (N + 1)
def fp(self, x):
if self.__arr[x] < 0:
return x
else:
self.__arr[x] = self.fp(self.__arr[x])
return self.__arr[x]
def add(self, x, y):
if x > y:
x, y = y, x
p... |
s203272530 | p02536 | u329319441 | 1601297176 | Python | Python (3.8.2) | py | Runtime Error | 151 | 11468 | 626 | N, M = map(int, input().split())
class uft:
def __init__(self, N):
self.__N = N
self.__arr = [-1] * (N + 1)
def fp(self, x):
if self.__arr[x] < 0:
return x
else:
self.__arr[x] = self.fp(self.__arr[x])
return self.__arr[x]
def add(self, x, y):
if x > y:
x, y = y, x
p... |
s870828200 | p02536 | u515740713 | 1601290469 | Python | PyPy3 (7.3.0) | py | Runtime Error | 97 | 68892 | 1791 | # -*- coding: Shift-JIS -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
class UnionFind:
"""素集合を木構造として管理する。"""
def __init__(self, n):
self.parent = [-1] * n
self.n = n
self.cnt = n
... |
s701044040 | p02536 | u318233626 | 1601264504 | Python | Python (3.8.2) | py | Runtime Error | 501 | 596748 | 657 | import sys
sys.setrecursionlimit(4100000)
def find(Data, x):
if Data[x] < 0:
return x
else:
Data[x] = find(Data, x)
return Data[x]
def unite(Data, a, b):
a, b = find(Data, a), find(Data, b)
if a != b:
if Data[a] < Data[b]:
Data[a] = Data[a] + Data[b]
... |
s830360219 | p02536 | u318233626 | 1601264242 | Python | Python (3.8.2) | py | Runtime Error | 483 | 596720 | 657 | import sys
sys.setrecursionlimit(4100000)
def find(Data, x):
if Data[x] < 0:
return x
else:
Data[x] = find(Data, x)
return Data[x]
def unite(Data, a, b):
a, b = find(Data, a), find(Data, b)
if a != b:
if Data[a] > Data[b]:
Data[a] = Data[a] + Data[b]
... |
s103874241 | p02536 | u318233626 | 1601264000 | Python | Python (3.8.2) | py | Runtime Error | 486 | 596780 | 629 | import sys
sys.setrecursionlimit(4100000)
def find(Data, x):
if Data[x] < 0:
return x
else:
Data[x] = find(Data, x)
return Data[x]
def unite(Data, a, b):
a, b = find(Data, a), find(Data, b)
if a != b:
if Data[a] > Data[b]:
Data[a] = Data[a] + Data[b]
... |
s660541168 | p02536 | u185193776 | 1601263865 | Python | Python (3.8.2) | py | Runtime Error | 728 | 69072 | 1274 | class DFS:
def __init__(self, n, cons):
nodes = [DFSNode(i) for i in range(n)]
for i, j in cons:
nodes[i].addAdjacent(nodes[j])
self.nodes = nodes
def clearVisited(self):
for node in self.nodes:
node.visited = False
def execute(self, rootId):
... |
s354583611 | p02536 | u318233626 | 1601263845 | Python | Python (3.8.2) | py | Runtime Error | 570 | 596772 | 629 | import sys
sys.setrecursionlimit(4100000)
def find(Tree, x):
if Tree[x] < 0:
return x
else:
Tree[x] = find(Tree, x)
return Tree[x]
def unite(Tree, a, b):
a, b = find(Tree, a), find(Tree, b)
if a != b:
if Tree[a] > Tree[b]:
Tree[a] = Tree[a] + Tree[b]
... |
s310690666 | p02536 | u318233626 | 1601263769 | Python | Python (3.8.2) | py | Runtime Error | 43 | 10716 | 586 | def find(Tree, x):
if Tree[x] < 0:
return x
else:
Tree[x] = find(Tree, x)
return Tree[x]
def unite(Tree, a, b):
a, b = find(Tree, a), find(Tree, b)
if a != b:
if Tree[a] > Tree[b]:
Tree[a] = Tree[a] + Tree[b]
Tree[b] = a
else:
... |
s738722178 | p02536 | u283312187 | 1601261167 | Python | PyPy3 (7.3.0) | py | Runtime Error | 270 | 108992 | 2556 | import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writa... |
s424337707 | p02536 | u473172054 | 1601257871 | Python | Python (3.8.2) | py | Runtime Error | 289 | 12008 | 225 | f = lambda x: x if p[x]<0 else f(p[x])
N,M = map(int,input().split())
p = [-1]*N
for _ in range(M):
A,B = map(lambda x:f(int(x)-1),input().split())
if A==B: continue
p[A] += p[B]
p[B] = A
print(sum(i<0 for i in p)-1)
|
s832026335 | p02536 | u414558682 | 1601257867 | Python | Python (3.8.2) | py | Runtime Error | 203 | 12944 | 1547 | 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):
... |
s986312976 | p02536 | u473172054 | 1601257510 | Python | Python (3.8.2) | py | Runtime Error | 118 | 35364 | 861 | n, m = map(int, input().split())
class MakeSet():
def __init__(self, x):
self.parent = x
self.rank = 0
def Union(x, y, par):
xRoot = Find(x, par)
yRoot = Find(y, par)
if par[xRoot].rank > par[yRoot].rank:
par[yRoot].parent = xRoot
elif par[xRoot].rank < par[yRoot].rank:
... |
s116586893 | p02536 | u602740328 | 1601255940 | Python | Python (3.8.2) | py | Runtime Error | 189 | 10832 | 242 | f = lambda x: x if p[x]<0 else f(p[x])
N,M = map(int,input().split())
p = [-1]*N
for _ in range(M):
A,B = map(lambda x:f(int(x)),input().split())
if A==B: continue
elif A<B: A,B=B,A
p[A] += p[B]
p[B] = A
print(sum(i<0 for i in p)-1) |
s414958892 | p02536 | u602740328 | 1601253420 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 30368 | 517 | from collections import deque
N,M = map(int,input().split())
E = {i: [] for i in range(N)}
for m in range(M):
A,B = map(int,input().split())
E[A].append(B)
E[B].append(A)
q = deque([0])
checked = [False]*N
ans = 0
while q and not(all(checked)):
n = q.popleft()
if checked[n]: continue
checked[n] = True
... |
s628412421 | p02536 | u295013286 | 1601250920 | Python | Python (3.8.2) | py | Runtime Error | 212 | 13460 | 408 | n,m=map(int, input().split())
roads=[]
for _ in range(m):
a,b=map(int, input().split())
if a<b:
roads.append([a,b].sort())
else:
roads.append([b,a].sort())
group=[i for i in range(n)]
group2=[]
while group2!=group:
group2=group
for road in roads:
group[road[1]-1]=group[road[0]-1]
counter=1
... |
s220991940 | p02536 | u295013286 | 1601250664 | Python | Python (3.8.2) | py | Runtime Error | 207 | 13592 | 362 | n,m=map(int, input().split())
roads=[]
for _ in range(m):
a,b=map(int, input().split())
roads.append([a,b].sort())
group=[i for i in range(n)]
group2=[]
while group2!=group:
group2=group
for road in roads:
group[road[1]-1]=group[road[0]-1]
counter=1
for i in range(n-1):
if group[i]!=group[i+1]:
... |
s820538946 | p02536 | u295013286 | 1601250137 | Python | Python (3.8.2) | py | Runtime Error | 208 | 13692 | 281 | n,m=map(int, input().split())
roads=[]
for _ in range(m):
a,b=map(int, input().split())
roads.append([a,b].sort())
group=[i for i in range(n)]
group2=[]
while group2!=group:
group2=group
for road in roads:
group[road[1]]=group[road[0]]
print(group[-1])
|
s612806450 | p02536 | u200916944 | 1601249227 | Python | PyPy3 (7.3.0) | py | Runtime Error | 235 | 86580 | 367 | #(N,M),*AB=[list(map(int, x.split())) for x in open(0).readlines()]
N,M=map(int,input().split())
AB=[list(map(int, input().split())) for _ in range(M)]
d={}
g=0
for a,b in AB:
if a in d:
d[b] = d[a]
elif b in d:
b[a] = d[b]
else:
g += 1
d[a] = d[b] = g
for i in range(1,N+1):
... |
s573739976 | p02536 | u200916944 | 1601249039 | Python | PyPy3 (7.3.0) | py | Runtime Error | 156 | 93476 | 281 | (N,M),*AB=[list(map(int, x.split())) for x in open(0).readlines()]
d={}
g=0
for a,b in AB:
if a in d:
d[b] = d[a]
elif b in d:
b[a] = d[b]
else:
g += 1
d[a] = d[b] = g
for i in range(1,N+1):
if not i in d:
g += 1
print(g - 1) |
s532987802 | p02536 | u200916944 | 1601247889 | Python | PyPy3 (7.3.0) | py | Runtime Error | 118 | 89676 | 305 | N,M=map(int, input().split())
AB=list(map(int, open(0).read().split()))
ss=[set()]
for i in range(0, len(AB), 2):
a=AB[i]
b=AB[i+1]
for s in ss:
if a in s or b in s:
s.add(a)
s.add(b)
break
else:
ss.add(set([a,b]))
print(N - len(ss) - M) |
s267807134 | p02536 | u098436028 | 1601241816 | Python | PyPy3 (7.3.0) | py | Runtime Error | 174 | 72248 | 131 | N,M=map(int,input().split())
L=[0]*N
for i in range(M):
A,B=map(int,input().split())
L[A] +=1
L[B] +=1
print(L.count(0)) |
s265170739 | p02536 | u306950978 | 1601241538 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 13132 | 1316 | 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 = ... |
s619853089 | p02536 | u306950978 | 1601241049 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2207 | 74776 | 800 | def find(n):
if root[n] < 0:
return n
else:
root[n] = find(root[n])
return root[n]
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return
if root[x] > root[y]:
x, y = y, x
root[x] += root[y]
root[y] = x
def size(x):
return -root[find(x)]
... |
s385405212 | p02536 | u722868069 | 1601240557 | Python | Python (3.8.2) | py | Runtime Error | 1633 | 36544 | 1404 | #最も上にいる親をたどる
# xは自分自身の番号を示す。
# r[x]は自分の親を示す。親がいない場合は-1を示す。
def root(x):
# case parent
if r[x] < 0:
return x
# case child
else:
return root(r[x])
#from operator import itemgetter
n, m = map(int, input().split())
road = [list(map(int,input().split())) for i in range(m)]
#root -1は上がいない、そのほかは親をもちその数字を表す。
... |
s603480141 | p02536 | u722868069 | 1601240369 | Python | Python (3.8.2) | py | Runtime Error | 2636 | 163652 | 1401 | #最も上にいる親をたどる
# xは自分自身の番号を示す。
# r[x]は自分の親を示す。親がいない場合は-1を示す。
def root(x):
# case parent
if r[x] < 0:
return x
# case child
else:
return root(r[x])
#from operator import itemgetter
n, m = map(int, input().split())
road = [list(map(int,input().split())) for i in range(m)]
#root -1は上がいない、そのほかは親をもちその数字を表す。
... |
s041441999 | p02536 | u998741086 | 1601240163 | Python | Python (3.8.2) | py | Runtime Error | 316 | 22368 | 1642 | #!/usr/bin/env python
n, m = map(int, input().split())
a = [0 for _ in range(m)]
b = [0 for _ in range(m)]
for i in range(m):
a[i], b[i] = map(int, input().split())
class UnionFind():
def __init__(self, n):
self.n = n
self.par = [i for i in range(n)]
self.rank = [0 for _ in range(n)]... |
s926611680 | p02536 | u959139907 | 1601237934 | Python | PyPy3 (7.3.0) | py | Runtime Error | 274 | 85948 | 2801 | # There are N cities numbered 1 through N, and M bidirectional roads numbered 1
# through M. Road i connects City A_i and City B_i.
#
# Snuke can perform the following operation zero or more times:
#
# * Choose two distinct cities that are not directly connected by a road, and
# build a new road between the two c... |
s747758447 | p02536 | u227082700 | 1601236729 | Python | Python (3.8.2) | py | Runtime Error | 26 | 8884 | 785 | class UnionFind:
def __init__(self, n):
self.n = [-1]*n
self.r = [0]*n
self.co = n
def find(self, x):
if self.n[x] < 0:
return x
else:
return self.n[x] = self.find(self.n[x])
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.... |
s981296089 | p02536 | u722868069 | 1601233912 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 36652 | 1404 | #最も上にいる親をたどる
# xは自分自身の番号を示す。
# r[x]は自分の親を示す。親がいない場合は-1を示す。
def root(x):
# case parent
if r[x] < 0:
return x
# case child
else:
return root(r[x])
#from operator import itemgetter
n, m = map(int, input().split())
road = [list(map(int,input().split())) for i in range(m)]
#root -1は上がいない、そのほかは親をもちその数字を表す。
... |
s777254569 | p02536 | u637289184 | 1601232690 | Python | Python (3.8.2) | py | Runtime Error | 25 | 9152 | 1267 | 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 = ... |
s967930499 | p02536 | u637289184 | 1601232586 | Python | Python (3.8.2) | py | Runtime Error | 27 | 9164 | 1271 | 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 = ... |
s527989132 | p02536 | u539367121 | 1601231006 | Python | Python (3.8.2) | py | Runtime Error | 531 | 116768 | 410 | import sys
sys.setrecursionlimit(10**5)
n,m=map(int,input().split())
g=[[] for i in range(10**5+10)]
for i in range(m):
a,b=map(lambda x:int(x)-1, input().split())
g[a].append(b)
g[b].append(a)
chk=[-1]*n
def dfs(s,v,cnt):
for u in g[s]:
if u==v: continue;
chk[u]=cnt
dfs(u,s,cnt)
cnt=0
for i in r... |
s245931131 | p02536 | u722868069 | 1601230976 | Python | Python (3.8.2) | py | Runtime Error | 442 | 36488 | 1320 | #最も上にいる親をたどる
# xは自分自身の番号を示す。
# r[x]は自分の親を示す。親がいない場合は-1を示す。
def root(x):
# case parent
if r[x] < 0:
return x
# case child
else:
return root(r[x])
#from operator import itemgetter
n, m = map(int, input().split())
road = [list(map(int,input().split())) for i in range(m)]
#root -1は上がいない、そのほかは親をもちその数字を表す。
... |
s987763131 | p02536 | u591808161 | 1601229286 | Python | PyPy3 (7.3.0) | py | Runtime Error | 268 | 90864 | 2251 | import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return... |
s199484924 | p02536 | u439063038 | 1601226414 | Python | PyPy3 (7.3.0) | py | Runtime Error | 617 | 545516 | 472 | import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())
root = [-1] * n
def find(x):
if root[x] < 0:
return x
else:
x = find(x)
return x
def unite(x, y):
x = find(x)
y = find(y)
if x == y:
return
root[x] += root[y]
root[y] = x
... |
s470544947 | p02536 | u439063038 | 1601225855 | Python | PyPy3 (7.3.0) | py | Runtime Error | 634 | 557200 | 484 | import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())
root = [-1] * n
def find(x):
if root[x] < 0:
return x
else:
root[x] = find(x)
return root[x]
def unite(x, y):
x = find(x)
y = find(y)
if x == y:
return
root[x] += root[y]
root[y]... |
s693710538 | p02536 | u439063038 | 1601225620 | Python | PyPy3 (7.3.0) | py | Runtime Error | 637 | 557412 | 509 | import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())
root = [-1] * (110000)
def find(x):
if root[x] < 0:
return x
else:
root[x] = find(x)
return root[x]
def unite(x, y):
x = find(x)
y = find(y)
if x == y:
return
root[x] += root[y]
... |
s915578296 | p02536 | u439063038 | 1601225464 | Python | PyPy3 (7.3.0) | py | Runtime Error | 652 | 557128 | 486 | import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())
root = [-1] * (110000)
def find(x):
if root[x] >= 0:
root[x] = find(x)
return root[x]
else:
return x
def unite(x, y):
x = find(x)
y = find(y)
if x != y:
root[x] += root[y]
root[y] = x... |
s725710333 | p02536 | u792720861 | 1601225459 | Python | Python (3.8.2) | py | Runtime Error | 547 | 12920 | 558 | class UnionFind():
def __init__(self, n):
self.p = list(range(n))
def find(self, x):
if self.p[x] == x: return x
self.p[x] = self.find(self.p[x])
return self.p[x]
def unite(self, x, y):
x, y = self.find(x), self.find(y)
if x != y: self.p[x] = y
N,M = ... |
s136627115 | p02536 | u439063038 | 1601225242 | Python | PyPy3 (7.3.0) | py | Runtime Error | 636 | 557500 | 486 | import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())
root = [-1] * (110000)
def find(x):
if root[x] >= 0:
root[x] = find(x)
return root[x]
else:
return x
def unite(a, b):
a = find(a)
b = find(b)
if a != b:
root[a] += root[b]
root[b] = a... |
s987712688 | p02536 | u439063038 | 1601224447 | Python | PyPy3 (7.3.0) | py | Runtime Error | 729 | 657808 | 499 | import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())
root = [-1] * (1100000)
def find(x):
if root[x] >= 0:
root[x] = find(x)
return root[x]
else:
return x
def unite(a, b):
a = find(a)
b = find(b)
if a != b:
root[a] += root[b]
root[b] = ... |
s736798817 | p02536 | u439063038 | 1601224066 | Python | PyPy3 (7.3.0) | py | Runtime Error | 110 | 69520 | 460 | import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())
root = [-1] * (110000)
def find(x):
if root[x] >= 0:
r = find(x)
root[x] = r
return r
def unite(a, b):
a = find(a)
b = find(b)
if a != b:
root[a] += root[b]
root[b] = a
for _ in range(m... |
s432817345 | p02536 | u439063038 | 1601224007 | Python | PyPy3 (7.3.0) | py | Runtime Error | 145 | 69128 | 377 | import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())
root = [-1] * (110000)
def find(x):
if root[x] >= 0:
r = find(x)
root[x] = r
return r
def unite(a, b):
a = find(a)
b = find(b)
if a != b:
root[a] += root[b]
root[b] = a
for _ in range(m... |
s348601070 | p02536 | u439063038 | 1601223706 | Python | PyPy3 (7.3.0) | py | Runtime Error | 270 | 74836 | 742 | n, m = map(int, input().split())
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]
d... |
s636120362 | p02536 | u439063038 | 1601223400 | Python | PyPy3 (7.3.0) | py | Runtime Error | 634 | 544948 | 445 | import sys
sys.setrecursionlimit(10 ** 9)
n, m = map(int, input().split())
root = [-1] * (110000)
def find(x):
if root[x] > 0:
x = find(x)
return x
def unite(a, b):
a = find(a)
b = find(b)
if a != b:
root[a] += root[b]
root[b] = a
for _ in range(m):
a, b = ma... |
s397791238 | p02536 | u439063038 | 1601223179 | Python | PyPy3 (7.3.0) | py | Runtime Error | 122 | 73800 | 402 | n, m = map(int, input().split())
root = [-1] * (110000)
def find(x):
if root[x] > 0:
x = find(x)
return x
def unite(a, b):
a = find(a)
b = find(b)
if a != b:
root[a] += root[b]
root[b] = a
for _ in range(m):
a, b = map(int, input().split())
unite(a, b)
an... |
s073814805 | p02536 | u252828980 | 1601221448 | Python | Python (3.8.2) | py | Runtime Error | 343 | 26988 | 399 | N, M = map(int, input().split())
AB = [[] for _ in range(N)]
for _ in range(M):
a,b = map(lambda x: int(x)-1, input().split())
AB[a].append(b)
AB[b].append(a)
def dfs(v):
visited[v] = 1
for i in AB[v]:
if visited[i]:
continue
dfs(i)
visited = [0]*N
cnt = 0
for i in ran... |
s767234047 | p02536 | u252828980 | 1601221264 | Python | Python (3.8.2) | py | Runtime Error | 327 | 27084 | 449 | n,m = map(int,input().split())
L = [[] for _ in range(n)]
for i in range(m):
a,b = map(lambda x:int(x)-1,input().split())
L[a].append(b)
L[b].append(a)
def dfs(i):
if visited[i]:
return
visited[i] = True
for j in L[i]:
if visited[j]:
continue
dfs(j)
... |
s961184850 | p02536 | u252828980 | 1601221201 | Python | Python (3.8.2) | py | Runtime Error | 344 | 26936 | 415 | n,m = map(int,input().split())
L = [[] for _ in range(n)]
for i in range(m):
a,b = map(lambda x:int(x)-1,input().split())
L[a].append(b)
L[b].append(a)
def dfs(i):
visited[i] = True
for j in L[i]:
if visited[j]:
continue
dfs(j)
visited = [False]*n
cnt = 0
... |
s443125052 | p02536 | u423966555 | 1601218292 | Python | Python (3.8.2) | py | Runtime Error | 286 | 26336 | 507 | def dfs(v):
visited[v] = 1
for i in AB[v]:
if visited[i]:
continue
dfs(i)
def main():
N, M = map(int, input().split())
AB = [[] for _ in range(N)]
for _ in range(M):
a,b = map(lambda x: int(x)-1, input().split())
AB[a].append(b)
AB[b].append(a)
... |
s504817234 | p02536 | u423966555 | 1601218162 | Python | Python (3.8.2) | py | Runtime Error | 308 | 27340 | 531 | def main():
N, M = map(int, input().split())
AB = [[] for _ in range(N)]
for _ in range(M):
a,b = map(lambda x: int(x)-1, input().split())
AB[a].append(b)
AB[b].append(a)
def dfs(v):
visited[v] = 1
for i in AB[v]:
if visited[i]:
conti... |
s724414509 | p02536 | u423966555 | 1601218046 | Python | Python (3.8.2) | py | Runtime Error | 296 | 27220 | 521 | def main():
N, M = map(int, input().split())
AB = [[] for _ in range(N)]
for _ in range(M):
a,b = map(lambda x: int(x)-1, input().split())
AB[a].append(b)
AB[b].append(a)
def dfs(v):
if visited[v]:
return
visited[v] = 1
for i in AB[v]:
... |
s014461715 | p02536 | u344813796 | 1601213998 | Python | Python (3.8.2) | py | Runtime Error | 194 | 18436 | 411 | m,n=map(int,input().split())
par=[i for i in range(m)]
def find(x):
if par[x] == x:
return x
else:
par[x] = find(par[x]) #経路圧縮
return par[x]
def same(x,y):
return find(x) == find(y)
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return 0
par[x] = y
for i i... |
s733449187 | p02536 | u010379708 | 1601212387 | Python | Python (3.8.2) | py | Runtime Error | 200 | 12640 | 1345 | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x) -> int:
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) -> Non... |
s358789589 | p02536 | u869790980 | 1601205739 | Python | PyPy2 (7.3.0) | py | Runtime Error | 68 | 64300 | 383 |
n,m = map(int, raw_input())
def g(u,parent):
if parent[u]!= u:
parent[u] = g(parent[u], parent)
return parent[u]
parent = {u:u for u in range(1, n+1)}
for _ in range(m):
u,v = map(int, raw_input().split())
pu,pv = g(u,parent), g(v,parent)
if pu!= pv:
parent[pu] = pv
ans = 0
for u ... |
s207716317 | p02536 | u500006160 | 1601204705 | Python | PyPy2 (7.3.0) | py | Runtime Error | 232 | 122916 | 526 | import sys
input = sys.stdin.readline
n,m = (int(x) for x in input().split())
visited = [False for _ in xrange(n)]
graph = dict(((i,[]) for i in xrange(n)))
def dfs(node):
if visited[node]:
return None
visited[node] = True
for next_node in graph[node]:
dfs(next_node)
return None
for... |
s822957280 | p02536 | u500006160 | 1601203729 | Python | Python (3.8.2) | py | Runtime Error | 335 | 28028 | 405 | from collections import defaultdict
n,m=map(int,input().split())
visited=[0]*n
d=defaultdict(list)
def dfs(n):
visited[n]=1
#print(visited)
for i in d[n]:
if visited[i]==0:
dfs(i)
for i in range (m):
a,b=map(int,input().split())
a,b=a-1,b-1
d[a].append(b)
d[b].append(a)... |
s328840069 | p02536 | u500006160 | 1601203607 | Python | Python (3.8.2) | py | Runtime Error | 310 | 28020 | 468 | from collections import defaultdict
n, m=map(int,input().split())
visited=[False for _ in range(n)]
graph = defaultdict(list)
def dfs(node):
visited[node]=1
for next_node in graph[node]:
if visited[next_node]==0:
dfs(next_node)
for _ in range(m):
a,b=map(int,input().split())
a,b=... |
s201035161 | p02536 | u500006160 | 1601203280 | Python | Python (3.8.2) | py | Runtime Error | 332 | 28008 | 483 | from collections import defaultdict
n,m = (int(x) for x in input().split())
visited = [False for _ in range(n)]
graph = defaultdict(list)
for _ in range(m):
u,v = (int(x)-1 for x in input().split())
graph[u].append(v)
graph[v].append(u)
def dfs(node):
if not visited[node]:
visited[node] = T... |
s301410899 | p02536 | u500006160 | 1601202773 | Python | Python (3.8.2) | py | Runtime Error | 387 | 34492 | 480 | n,m = (int(x) for x in input().split())
visited = [False for _ in range(n)]
graph = dict(((i,[]) for i in range(n)))
def dfs(node):
if visited[node]:
return None
visited[node] = True
for next_node in graph[node]:
dfs(next_node)
return None
for _ in range(m):
u,v = (int(x) - 1 for x... |
s545006600 | p02536 | u500006160 | 1601202517 | Python | PyPy2 (7.3.0) | py | Runtime Error | 417 | 124204 | 796 | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
n,m = (in... |
s211322098 | p02536 | u500006160 | 1601202225 | Python | PyPy2 (7.3.0) | py | Runtime Error | 501 | 127504 | 834 | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
n,m = (in... |
s139945847 | p02536 | u397080265 | 1601196434 | Python | PyPy3 (7.3.0) | py | Runtime Error | 233 | 115868 | 4942 | #Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threadi... |
s478173963 | p02536 | u729133443 | 1601194487 | Python | Python (3.8.2) | py | Runtime Error | 350 | 53524 | 193 | (n,m),*a=[map(int,t.split())for t in open(0)]
p=[-1]*-~n
for a in a:
b,a=sorted(map(r:=lambda x:x*(p[x]<0)or r(p[x]),a),key=p.__getitem__)
if a-b:p[a]+=p[b];p[b]=a
print(sum(i<0for i in p)-2) |
s274776308 | p02536 | u729133443 | 1601194374 | Python | Python (3.8.2) | py | Runtime Error | 365 | 53524 | 167 | (n,m),*a=[map(int,t.split())for t in open(0)]
p=[-1]*-~n
for a in a:
a,b=map(r:=lambda x:x*(p[x]<0)or r(p[x]),a)
if a-b:p[a]+=p[b];p[b]=a
print(sum(i<0for i in p)-2) |
s954920185 | p02536 | u694665829 | 1601193235 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9020 | 559 | from collections import deque
n,m = map(int,input().split())
g = [[] for _ in range(n)]
for i in range(m):
a, b = map(int,input().split())
g[a-1].append(b-1)
g[b-1].append(a-1)
checked = [False]*n
q = deque([])
cnt = 0
#連結成分のカウント
for i in range(n):
if checked[i]:
continue
checked[i] = Tru... |
s566756348 | p02536 | u224993839 | 1601192524 | Python | PyPy3 (7.3.0) | py | Runtime Error | 363 | 152780 | 372 |
from collections import defaultdict
visited=set()
def dfs(visited,graph,node):
if node not in visited:
visited.add(node)
for neighbour in graph[node]:
dfs(visited,graph,neighbour)
n,m=map(int,input().split())
d=defaultdict(list)
for i in range(m):
a,b=map(int,input().split())
d[a].append(b)
d[b].append(... |
s221624836 | p02536 | u224993839 | 1601192404 | Python | PyPy3 (7.3.0) | py | Runtime Error | 392 | 161396 | 367 |
from collections import defaultdict
visited=set()
def dfs(visited,graph,node):
if node not in visited:
visited.add(node)
for neighbour in graph[node]:
dfs(visited,graph,neighbour)
n,m=map(int,input().split())
d=defaultdict(list)
for i in range(m):
a,b=map(int,input().split())
d[a].append(b)
d[b].append(... |
s621051951 | p02536 | u216928054 | 1601189829 | Python | PyPy3 (7.3.0) | py | Runtime Error | 86 | 68740 | 1322 | """
Union-Find Tree / Disjoint Set Union (DSU)
"""
def init_unionfind(N):
global parent, rank, NUM_VERTEX
NUM_VERTEX = N
parent = [-1] * N
rank = [0] * N
def find_root(x):
p = parent[x]
if p == -1:
return x
p2 = find_root(p)
parent[x] = p2
return p2
def unite(x, y):
... |
s251312525 | p02536 | u332657092 | 1601189470 | Python | PyPy3 (7.3.0) | py | Runtime Error | 268 | 81600 | 1330 | 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 = ... |
s009550572 | p02536 | u332657092 | 1601189195 | Python | PyPy3 (7.3.0) | py | Runtime Error | 277 | 75276 | 1300 | 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 = ... |
s139090892 | p02536 | u197922478 | 1601187849 | Python | PyPy3 (7.3.0) | py | Runtime Error | 113 | 71460 | 1923 | class UnionFind:
def __init__(self,n):
self.param = [-1]*N
self.tree = [0]*N
def clustering(self,x,y):
x ,y =min(x,y), max(x,y)
#小さいほうが未知
if self.param[x] == -1:
#どちらも未知
if self.param[y] == -1:
self.param[x] = y
... |
s145505297 | p02536 | u197922478 | 1601187478 | Python | PyPy3 (7.3.0) | py | Runtime Error | 86 | 71536 | 1805 | class UnionFind:
def __init__(self,n):
self.param = [-1]*N
self.tree = [0]*N
def clustering(self,x,y):
x ,y =min(x,y), max(x,y)
#小さいほうが未知
if self.param[x] == -1:
#どちらも未知
if self.param[y] == -1:
self.param[x] = y
... |
s584677630 | p02536 | u404034840 | 1601187361 | Python | Python (3.8.2) | py | Runtime Error | 49 | 9256 | 635 | n,m = map(int,input().split())
a = []
cnt = 0
dl = []
for i in range(m):
x,y = map(int,input().split())
if i == 0:
a.append([])
a[0].append(x)
a[0].append(y)
else:
f = -1
for j in range(len(a)):
if f == -1 and (x in a[j] or y in a[j]):
a[j].append(x)
a[j].append(y)
... |
s125065103 | p02536 | u197922478 | 1601186865 | Python | PyPy3 (7.3.0) | py | Runtime Error | 87 | 71688 | 1805 | class UnionFind:
def __init__(self,n):
self.param = [-1]*N
self.tree = [0]*N
def clustering(self,x,y):
x ,y =min(x,y), max(x,y)
#小さいほうが未知
if self.param[x] == -1:
#どちらも未知
if self.param[y] == -1:
self.param[x] = y
... |
s382333859 | p02536 | u381585104 | 1601186480 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9008 | 3275 | #![allow(dead_code,unused_variables)]
use proconio::{fastout, input};
#[fastout]
fn main() {
input! {
n: usize,
m: usize,
}
let mut uf = Dsu::new(n);
for i in 0..m{
input!(a:usize,b:usize);
uf.merge(a-1,b-1);
}
println!("{}",uf.groups().len()-1);
}
//https://gith... |
s212614510 | p02536 | u437351386 | 1601186096 | Python | PyPy3 (7.3.0) | py | Runtime Error | 313 | 82336 | 931 | n,m=map(int,input().split())
#Union-Find木
#par[i]:iの親 deep[i]:iの深さ size[i]:iの大きさ
par=[i for i in range(n)]
deep=[1]*n
size=[1]*n
#親を見つける
def find(x):
if par[x]==x:
return x
else:
return find(par[x])
#二つのグループを統合する
def unite(x,y):
x=find(x)
y=find(y)
if x==y:
return
if deep[x]<deep[y]:
par[x... |
s701497403 | p02536 | u197922478 | 1601185758 | Python | PyPy3 (7.3.0) | py | Runtime Error | 122 | 74596 | 1752 | class UnionFind:
def __init__(self,n):
self.param = [-1]*N
self.tree = [0]*N
def clustering(self,x,y):
x ,y =min(x,y), max(x,y)
#小さいほうが未知
if self.param[x] == -1:
#どちらも未知
if self.param[y] == -1:
self.param[x] = y
... |
s627668593 | p02536 | u197922478 | 1601185569 | Python | PyPy3 (7.3.0) | py | Runtime Error | 3026 | 292172 | 1791 | class UnionFind:
def __init__(self,n):
self.param = [-1]*N
self.tree = [0]*N
def clustering(self,x,y):
x ,y =min(x,y), max(x,y)
#小さいほうが未知
if self.param[x] == -1:
#どちらも未知
if self.param[y] == -1:
self.param[x] = y
... |
s704482481 | p02536 | u197922478 | 1601185075 | Python | PyPy3 (7.3.0) | py | Runtime Error | 116 | 74568 | 1940 | N, M = map(int, input().split())
class UnionFind:
def __init__(self,n):
self.param = [-1]*N
self.tree = [0]*N
def unite(self,x,y):
pass
#親を探す
def search(self,x,y):
pass
def clustering(self,x,y):
x ,y =min(x,y), max(x,y)
#小さいほうが未... |
s366541719 | p02536 | u734876600 | 1601185068 | Python | Python (3.8.2) | py | Runtime Error | 322 | 30768 | 453 | n,m = map(int, input().split())
li = [[] for _ in range(n)]
for i in range(m):
a,b = map(int, input().split())
a -= 1
b -= 1
li[a].append(b)
li[b].append(a)
nodes = [_ for _ in range(n)]
group = [1]*n
def dfs(node, group):
s = li[node]
group[node]=0
for v in s:
if group[v]!=0:
... |
s150822983 | p02536 | u197922478 | 1601184975 | Python | PyPy3 (7.3.0) | py | Runtime Error | 119 | 74672 | 1921 | N, M = map(int, input().split())
class UnionFind:
def __init__(self,n):
self.param = [-1]*N
self.tree = [0]*N
def unite(self,x,y):
pass
#親を探す
def search(self,x,y):
pass
def clustering(self,x,y):
x ,y =min(x,y), max(x,y)
#小さいほうが未... |
s478456634 | p02536 | u734876600 | 1601184720 | Python | Python (3.8.2) | py | Runtime Error | 327 | 30892 | 452 | n,m = map(int, input().split())
li = [[] for _ in range(n)]
for i in range(m):
a,b = map(int, input().split())
a -= 1
b -= 1
li[a].append(b)
li[b].append(a)
nodes = [i for i in range(n)]
group = [1]*n
def dfs(node, group):
s = li[node]
group[node]=0
for v in s:
if group[v]!=0:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.