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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s005115557 | p02573 | u940652437 | 1599423187 | Python | Python (3.8.2) | py | Runtime Error | 2208 | 100992 | 297 | n,m = map(int,input().split())
tomo =[]
a = list(map(int,input().split()))
tomo += a
for i in range(m-1):
a,b=map(int,input().split())
for j in range(len(tomo)):
if(a == tomo[j] or b == tomo[j]):
tomo.append(a)
tomo.append(b)
ans = set(tomo)
print(len(ans)) |
s739704582 | p02573 | u940652437 | 1599423052 | Python | Python (3.8.2) | py | Runtime Error | 2208 | 95272 | 309 | n,m = map(int,input().split())
tomo =[]
a = list(map(int,input().split()))
tomo += a
for i in range(m-1):
a,b=map(int,input().split())
for j in range(len(tomo)):
if(a == tomo[j] or b == tomo[j]):
tomo.append(a)
tomo.append(b)
ans = set(tomo)
#print(ans)
print(len(ans)) |
s708860579 | p02573 | u940652437 | 1599423028 | Python | Python (3.8.2) | py | Runtime Error | 2208 | 98648 | 313 | n,m = map(int,input().split())
tomo =[]
a = list(map(int,input().split()))
tomo += a
for i in range(m-1):
a,b=map(int,input().split())
for j in range(len(tomo)):
if(a == tomo[j] or b == tomo[j]):
tomo.append(a)
tomo.append(b)
ans = set(tomo)
print(ans)
print(len(ans))
|
s781198483 | p02573 | u100858029 | 1599422069 | Python | Python (3.8.2) | py | Runtime Error | 780 | 214040 | 827 | '''
We can show that if u and v belong to the same connected component, then they are friends w/ each other
So everyone in a given connected component is friends with one another
So everyone in a given connected component must be separated into different groups
If we have a CC of with sz nodes in it, then we need ... |
s192587049 | p02573 | u056358163 | 1599408632 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 51192 | 879 | N, M = map(int, input().split())
group_list = []
group_index = [0] * N
for _ in range(M):
a, b = map(int, input().split())
if group_index[a-1] == 0 and group_index[b-1] == 0:
group_index[a-1] = len(group_list) + 1
group_index[b-1] = len(group_list) + 1
group_list.append(set([a, b]))
... |
s005697417 | p02573 | u274080981 | 1599408033 | Python | Python (3.8.2) | py | Runtime Error | 2216 | 386960 | 592 | n, m = map(int, input().split())
ans=0
relationships = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
relationships[i].sort()
relationships.sort()
groups = []
groups.append(set(relationships[0]))
for i in range(1, m):
for j in range(len(groups)):
if relationships[i][0] in groups... |
s451375040 | p02573 | u056358163 | 1599407721 | Python | Python (3.8.2) | py | Runtime Error | 735 | 47472 | 989 | N, M = map(int, input().split())
A = []
B = []
for _ in range(M):
a, b = map(int, input().split())
A.append(a)
B.append(b)
group_list = []
group_index = [0] * N
last_group = 1
for a, b in zip(A, B):
if group_index[a-1] == 0 and group_index[b-1] == 0:
group_index[a-1] = last_group
gro... |
s888148773 | p02573 | u351480677 | 1599407559 | Python | Python (3.8.2) | py | Runtime Error | 441 | 50208 | 759 | import sys
class UnionFind():
def __init__(self, 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.fin... |
s430096521 | p02573 | u056358163 | 1599406922 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 46272 | 696 | from collections import defaultdict
from itertools import combinations
N, M = map(int, input().split())
A = []
B = []
for _ in range(M):
a, b = map(int, input().split())
A.append(a)
B.append(b)
group_list = []
#D = defaultdict(set)
for a, b in zip(A, B):
if len(group_list) == 0:
group_list.ap... |
s320070731 | p02573 | u549579601 | 1599406880 | Python | PyPy3 (7.3.0) | py | Runtime Error | 789 | 146976 | 502 | import collections
n, m = map(int, input().split())
A = [0] * n
mamimum = 1
B = []
C = []
for i in range(m):
b, c = map(int, input().split())
B.append(b)
C.append(c)
D = zip(B, C)
D = sorted(D)
B, C = zip(*D)
for i, j in zip(B, C):
i -= 1
j -= 1
if A[i] == 0 and A[j] == 0:
A[i] = ... |
s637505266 | p02573 | u100858029 | 1599404759 | Python | Python (3.8.2) | py | Runtime Error | 28 | 9012 | 823 | '''
We can show that if u and v belong to the same connected component, then they are friends w/ each other
So everyone in a given connected component is friends with one another
So everyone in a given connected component must be separated into different groups
If we have a CC of with sz nodes in it, then we need ... |
s315122143 | p02573 | u100858029 | 1599404637 | Python | PyPy3 (7.3.0) | py | Runtime Error | 579 | 154360 | 784 | '''
We can show that if u and v belong to the same connected component, then they are friends w/ each other
So everyone in a given connected component is friends with one another
So everyone in a given connected component must be separated into different groups
If we have a CC of with sz nodes in it, then we need ... |
s600087716 | p02573 | u666721654 | 1599400574 | Python | PyPy3 (7.3.0) | py | Runtime Error | 161 | 67944 | 863 | import numpy as np
class UnionFind:
def __init__(self, sz: int):
self._par: np.array = np.full(sz + 1, -1)
def root(self, a: int):
if self._par[a] < 0:
return a
self._par[a] = self.root(self._par[a])
return self._par[a]
def size(self, a: int):
retur... |
s995174208 | p02573 | u427427681 | 1599399613 | Python | Python (3.8.2) | py | Runtime Error | 2228 | 642836 | 732 | N,M = tuple(map(int,input().split()))
# matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = list(range(N))
# [所属先,[所属メンバー]]
gplist = [[i] for i in range(N)]
def getgroup(a):
A = friendlist[a]
if A == a:
return a
else:
return getgroup(A)... |
s772519999 | p02573 | u894521144 | 1599392284 | Python | Python (3.8.2) | py | Runtime Error | 32 | 9412 | 1401 | from collections import Counter
# 再帰回数のエラー?と思われるので再帰上限を変更 10**3 → 10**9
# 変更したら RE がなくなったのでおそらくこれのせいで通らなかった
import sys
sys.setrecursionlimit(10 ** 9)
lst = [n for n in range(N)] # 初期値はすべてがそれぞれ根である状態
def get_root(x): # 根を得る関数
if lst[x] == x: # それ自身が根である場合
return x
else: # 根が別のものである場合
lst[... |
s867547639 | p02573 | u449775273 | 1599391990 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 26456 | 384 | n, m =map(int,input().split())
l = [{int(x) for x in input().split()}]
ans = 0
for _ in range(m-1):
a = {int(x) for x in input().split()}
for j, s in enumerate(l):
if s & a:
l[j] |= a
ans = max(ans, len(l[j]))
if ans >= n:
print(ans)
ex... |
s683724664 | p02573 | u894521144 | 1599391862 | Python | Python (3.8.2) | py | Runtime Error | 828 | 51932 | 1118 | from collections import Counter
def main(N, M, C):
lst = [n for n in range(N)] # 初期値はすべてがそれぞれ根である状態
def get_root(x): # 根を得る関数
if lst[x] == x: # それ自身が根である場合
return x
else: # 根が別のものである場合
lst[x] = get_root(lst[x]) # 経路圧縮あり (ある種「メモ再帰化」)
return lst[x]
... |
s330886107 | p02573 | u894521144 | 1599391748 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 53100 | 1120 | from collections import Counter
def main(N, M, C):
lst = [n for n in range(N)] # 初期値はすべてがそれぞれ根である状態
def get_root(x): # 根を得る関数
if lst[x] == x: # それ自身が根である場合
return x
else: # 根が別のものである場合
# lst[x] = get_root(lst[x]) # 経路圧縮あり (ある種「メモ再帰化」)
# return lst[x]
... |
s809968498 | p02573 | u449775273 | 1599391063 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 26268 | 310 | n, m =map(int,input().split())
l = [{int(x) for x in input().split()}]
ans = 0
for _ in range(m-1):
a = {int(x) for x in input().split()}
for j, s in enumerate(l):
if s & a:
l[j] |= a
break
else:
l.append(a)
for s in l:
ans = max(ans, len(s))
print(ans)
|
s056815429 | p02573 | u408375121 | 1599375962 | Python | Python (3.8.2) | py | Runtime Error | 254 | 56268 | 392 | n, m = map(int, input().split())
group = [set() for _ in range(n+1)]
for _ in range(m):
a, b = map(int, input())
group[a].add(b)
group[b].add(a)
lst = [True] * (n+1)
ans = 0
for i in range(1, n+1):
if lst[i]:
friends = group[i]
for friend in group[i]:
friends = friends | group[friend]
lst[f... |
s860565986 | p02573 | u427427681 | 1599342387 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 47832 | 940 | N,M = tuple(map(int,input().split()))
matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = [0 for i in range(N)]
gplist = [[-1]]
def match(ab):
a,b=ab
gpa=friendlist[a]
gpb=friendlist[b]
if bool(gpa) and gpa==gpb:
return
elif not bool(gpa... |
s990115774 | p02573 | u427427681 | 1599342056 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 43888 | 948 | N,M = tuple(map(int,input().split()))
matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = [0 for i in range(N)]
gplist = [[]]
def match(ab):
a,b=ab
gpa=friendlist[a]
gpb=friendlist[b]
if bool(gpa) and gpa==gpb:
return
elif not bool(gpa) ... |
s954933300 | p02573 | u200243669 | 1599318952 | Python | Python (3.8.2) | py | Runtime Error | 537 | 14444 | 722 | class UnionFind():
def __init__(self,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)
... |
s153169054 | p02573 | u229950162 | 1599308223 | Python | Python (3.8.2) | py | Runtime Error | 2373 | 147528 | 543 | n, m = list(map(int, input().rstrip().split(" ")))
members = [1 for i in range(n)]
max_idx = 0
for mm in range(m):
print(members)
a0, b0 = list(map(int, input().rstrip().split(" ")))
a = a0
b = b0
while members[a-1] < 0:
a = -members[a-1]
members[a0-1] = -a
while members[b-1] < 0:
b = -members[b... |
s271805546 | p02573 | u229950162 | 1599306985 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 10828 | 478 | n, m = list(map(int, input().rstrip().split(" ")))
members = [1 for i in range(n)]
max_idx = 0
for mm in range(m):
a0, b0 = list(map(int, input().rstrip().split(" ")))
a = a0
b = b0
while members[a-1] < 0:
a = -members[a-1]
while members[b-1] < 0:
b = -members[b-1]
members[a0-1] = -a
members[b0-1]... |
s821148507 | p02573 | u407778590 | 1599304969 | Python | Python (3.8.2) | py | Runtime Error | 907 | 16304 | 529 | def get_group_root(x):
if parent[x] < 0:
return x
return get_group_root(parent[x])
[N, M] = map(int, input().split())
parent = [-1] * N # 親の友人
for i in range(M):
[A,B] = map(int, input().split())
A -= 1
B -= 1
groupA = get_group_root(A)
groupB = get_group_root(B)
if groupA =... |
s201853877 | p02573 | u808817704 | 1599297211 | Python | PyPy3 (7.3.0) | py | Runtime Error | 515 | 168432 | 924 | from collections import Counter
class UnionFind:
def __init__(self, N: int) -> None:
self.par = [i for i in range(N)]
def root(self, x: int) -> bool:
if self.par[x] == x: #親が自分自身なら頂点
return x
else:
self.par[x] = self.root(self.par[x])
return self... |
s363256694 | p02573 | u617384447 | 1599275811 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2212 | 228692 | 456 |
N, M = map(int, input().split()) # M pieces of information for N people
# if a parent, -1 * number of members
# else index of its parent
UF = [-1] * N
def root(x):
if UF[x] < 0:
return x
else:
return root(UF[x])
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
... |
s543524616 | p02573 | u522945737 | 1599267778 | Python | Python (3.8.2) | py | Runtime Error | 25 | 8916 | 1427 | import copy
def dfs(k,E,A,B):
# print("lenA is "+str(len(A)))
for i in range(len(A)):
# print("i is "+str(i))
# print("k is "+str(k))
if i >= len(A):
# print("damedesu")
break
# print("A[i] is "+str(A[i]))
# print("B[i] is "+str(B[i]))
if k == ... |
s035622320 | p02573 | u188305619 | 1599258095 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 13052 | 582 | N, M = map(int,input().split())
pairs = []
for i in [0]*M:
inp = sorted(list(map(int,input().split())))
if inp not in pairs:
pairs.append(inp)
def solver(N,M,pairs):
group_list = []
for i in pairs:
pair = sorted(i)
for j in range(len(group_list)):
if pair[1] in group_... |
s924497862 | p02573 | u719260857 | 1599252294 | Python | Python (3.8.2) | py | Runtime Error | 994 | 187260 | 433 | import collections
import sys
import resource
sys.setrecursionlimit(200000)
n, m = map(int, input().split(' '))
f = [x for x in range(n)]
def find(x):
if f[x] == x:
return x
root = find(f[x])
f[x] = root
return root
for i in range(m):
a, b = map(int, input().split(' '))
a -= 1
b -= 1
if find(a) ... |
s907722466 | p02573 | u533232830 | 1599248045 | Python | PyPy3 (7.3.0) | py | Runtime Error | 487 | 111724 | 537 | from collections import deque
N, M = map(int, input().split())
friends = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a, b = a-1, b-1
friends[a].append(b)
friends[b].append(a)
check = [False] * N
ans = 0
for i in range(N):
if check[i] == False:
check[i] = True
D = deq... |
s481065982 | p02573 | u533232830 | 1599247985 | Python | PyPy3 (7.3.0) | py | Runtime Error | 433 | 111692 | 536 | from collections import deque
N, M = map(int, input().split())
friends = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a, b = a-1, b-1
friends[a].append(b)
friends[b].append(a)
check = [False] * N
ans = 0
for i in range(N):
if check[i] == False:
check[i] = True
D = deq... |
s044609642 | p02573 | u216069198 | 1599246274 | Python | Python (3.8.2) | py | Runtime Error | 735 | 44696 | 488 | n,m=map(int,input().split())
g=[]
for i in range(n+10):
g.append([])
for i in range(m):
a,b=map(int,input().split())
g[a].append(b)
g[b].append(a)
ans=0
vis=[False]*(n+10)
#vis[1]=True
def dfs(n):
ret=0
if vis[n]:
return 0
else:
vis[n]=True
ret+=1
for i i... |
s664743096 | p02573 | u216069198 | 1599246196 | Python | Python (3.8.2) | py | Runtime Error | 728 | 44692 | 486 | n,m=map(int,input().split())
g=[]
for i in range(n+1):
g.append([])
for i in range(m):
a,b=map(int,input().split())
g[a].append(b)
g[b].append(a)
ans=0
vis=[False]*(n+1)
#vis[1]=True
def dfs(n):
ret=0
if vis[n]:
return 0
else:
vis[n]=True
ret+=1
for i in ... |
s651208807 | p02573 | u719260857 | 1599239228 | Python | Python (3.8.2) | py | Runtime Error | 723 | 31916 | 423 | import collections
import sys
n, m = map(int, input().split(' '))
if m == 0:
print(1)
sys.exit()
f = [x for x in range(n)]
def find(x):
if f[x] == x:
return x
root = find(f[x])
f[x] = root
return root
for i in range(m):
a, b = map(int, input().split(' '))
a -= 1
b -= 1
if find(a) != find(b)... |
s242481920 | p02573 | u719260857 | 1599239097 | Python | Python (3.8.2) | py | Runtime Error | 765 | 32228 | 385 | import collections
n, m = map(int, input().split(' '))
f = [x for x in range(n)]
def find(x):
if f[x] == x:
return x
root = find(f[x])
f[x] = root
return root
for i in range(m):
a, b = map(int, input().split(' '))
a -= 1
b -= 1
if find(a) != find(b):
f[find(a)] = find(b)
for i in range(n):
... |
s077397957 | p02573 | u945157177 | 1599232856 | Python | PyPy3 (7.3.0) | py | Runtime Error | 564 | 82844 | 656 | def readInt():
return list(map(int, input().split()))
n, m = readInt()
root = [-1] * n
def r(x):
# print("root[x]=",root[x])
if root[x] < 0:
# print("r(x)=",x)
return x
else:
root[x] = r(root[x])
# print(root[x])
return root[x]
def unite(x, y):
x = r(x)
... |
s370034908 | p02573 | u896726004 | 1599231581 | Python | Python (3.8.2) | py | Runtime Error | 589 | 14564 | 1635 | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# xの属する木の根を求める
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
# xとyの属す... |
s455658049 | p02573 | u334703235 | 1599231383 | Python | Python (3.8.2) | py | Runtime Error | 2260 | 1597660 | 878 | import numpy as np
N,M = map(int,input().split())
li = np.zeros((N,N)).tolist()
for i in range(M):
Ai, Bi =map(int,input().split())
li[Ai-1][Bi-1] = 1
li[Bi-1][Ai-1] = 1
que = list()
idx = list(range(0,N)) #index list for second loop
maxC = 0
while True:
if len(idx) == 0:
break
startfri... |
s266476395 | p02573 | u334703235 | 1599231295 | Python | Python (3.8.2) | py | Runtime Error | 2247 | 1598056 | 877 | import numpy as np
N,M = map(int,input().split())
li = np.zeros((N,N)).tolist()
for i in range(M):
Ai, Bi =map(int,input().split())
li[Ai-1][Bi-1] = 1
li[Bi-1][Ai-1] = 1
que = list()
idx = list(range(0,N)) #index list for second loop
maxC = 0
while True:
if len(idx) == 0:
break
startfri... |
s545636351 | p02573 | u334703235 | 1599231269 | Python | PyPy3 (7.3.0) | py | Runtime Error | 95 | 74784 | 877 | import numpy as np
N,M = map(int,input().split())
li = np.zeros((N,N)).tolist()
for i in range(M):
Ai, Bi =map(int,input().split())
li[Ai-1][Bi-1] = 1
li[Bi-1][Ai-1] = 1
que = list()
idx = list(range(0,N)) #index list for second loop
maxC = 0
while True:
if len(idx) == 0:
break
startfri... |
s700301702 | p02573 | u458967973 | 1599227462 | Python | Python (3.8.2) | py | Runtime Error | 2373 | 150528 | 694 | n, m = map(int, input().split())
data2 = []
for i in range(m):
data2.append(input().split())
graph = [[] for i in range(n)]
for i in range(m):
a, b = map(lambda z: int(z) - 1, data2[m])
graph[a].append(b)
graph[b].append(a)
print(graph)
size = [0 for i in range(n)]
check = [True for i in range(n)]
fo... |
s059349898 | p02573 | u472696272 | 1599227037 | Python | Python (3.8.2) | py | Runtime Error | 433 | 16076 | 616 | n,m = map(int,input().split())
friendship = [0] * (n+1)
set_mark = 0
for i in range(m):
p1,p2 = map(int,input().split())
if friendship[p1] == 0 and friendship[p2] == 0:
set_mark += 1
friendship[p1] = friendship[p2] = set_mark
elif friendship[p1] == 0 and friendship[p2] != 0:
friendship[p1] = friends... |
s815036084 | p02573 | u472696272 | 1599226995 | Python | Python (3.8.2) | py | Runtime Error | 464 | 15832 | 614 | n,m = map(int,input().split())
friendship = [0] * (n+1)
set_mark = 0
for i in range(m):
p1,p2 = map(int,input().split())
if friendship[p1] == 0 and friendship[p2] == 0:
set_mark += 1
friendship[p1] = friendship[p2] = set_mark
elif friendship[p1] == 0 and friendship[p2] != 0:
friendship[p1] = friends... |
s015625030 | p02573 | u113310313 | 1599226030 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 52448 | 555 | from collections import defaultdict
N, M = map(int, input().split())
F = defaultdict(list)
max_size = 0
for _ in range(M):
A, B = map(int, input().split())
if B not in F[A]:
F[A].append(B)
if A not in F[B]:
F[B].append(A)
def dfs(i):
vis.append(i)
size = 0
for j in F[i]:
... |
s170645988 | p02573 | u197909530 | 1599212329 | Python | PyPy3 (7.3.0) | py | Runtime Error | 86 | 74720 | 503 | #ABC177
#D - Friends
N,M=map(int,input().split())
friends=[]
member=[]
for i in range(M):
x,y=map(lambda x :int(x)-1,input().split())
j=sorted[x,y]
if j in friends:
friends.append(j)
member.extend([x,y])
member2=[i for i in set(member) if member.count(i)>1 ]
for i in member2:
a=[k for j in friend... |
s449899695 | p02573 | u197909530 | 1599207831 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2212 | 269396 | 540 | #ABC177
#D - Friends
N,M=map(int,input().split())
friends=[[i] for i in range(N)]
member=[]
for i in range(M):
x,y=map(lambda x :int(x)-1,input().split())
friends[x].append(y)
friends[y].append(x)
member.extend([x,y])
friends=[sorted(set(i)) for i in friends if len(i)!=1]
member=sorted(set(member))
for i ... |
s606673727 | p02573 | u417365712 | 1599183063 | Python | Python (3.8.2) | py | Runtime Error | 327 | 57280 | 1178 | class UnionFind():
def __init__(self, n):
self._n = n
self._table = [-1]*n
def _root(self, x):
stack = []
while self._table[x] >= 0:
stack.append(x)
x = self._table[x]
for y in stack:
self._table[y] = x
return x
def un... |
s484487682 | p02573 | u237380797 | 1599175897 | Python | PyPy3 (7.3.0) | py | Runtime Error | 91 | 74592 | 1730 | from collections import defaultdict
g=defaultdict(set)
n,m=map(int,input().split())
count=n
visited = [True]*(n+1)
visited1=[False]*(n+1)
for i in range(m):
u,v=map(int,input().split())
visited[u]=False
visited[v]=False
if visited1[u]==False:
visited1[u]=True
count-=1
if visited1[v]... |
s881904823 | p02573 | u153047519 | 1599174563 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9024 | 621 | class union:
def __init__(self, box):
self.r = []
for i in range(box):
self.r.append(-1)
def root(self, x):
if self.r[x] < 0:
return x
return self.r[x] = root(self.r[x])
def add(self, a, b):
a = root(a)
b = root(b)
if a == b:
return False
if self.r[a] > self... |
s808006103 | p02573 | u794173881 | 1599171119 | Python | PyPy3 (7.3.0) | py | Runtime Error | 466 | 111160 | 1338 | class UnionFind:
"""素集合を木構造として管理する"""
def __init__(self, n):
self.parent = [-1] * n
self.cnt = n
def root(self, x):
"""要素xの根を求める"""
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.root(self.parent[x])
return self.parent... |
s835006898 | p02573 | u181412342 | 1599165164 | Python | PyPy3 (7.3.0) | py | Runtime Error | 231 | 116708 | 2059 | import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import re... |
s607654863 | p02573 | u181412342 | 1599163791 | Python | PyPy3 (7.3.0) | py | Runtime Error | 1110 | 586140 | 1776 | import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import re... |
s605996421 | p02573 | u181412342 | 1599163751 | Python | PyPy3 (7.3.0) | py | Runtime Error | 1156 | 582284 | 1777 | import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import re... |
s787092222 | p02573 | u181412342 | 1599163714 | Python | PyPy3 (7.3.0) | py | Runtime Error | 1103 | 583396 | 1776 | import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import re... |
s362816999 | p02573 | u181412342 | 1599163668 | Python | PyPy3 (7.3.0) | py | Runtime Error | 1154 | 584792 | 1777 | import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import re... |
s998413133 | p02573 | u181412342 | 1599163620 | Python | PyPy3 (7.3.0) | py | Runtime Error | 121 | 74312 | 1776 | import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import re... |
s064288607 | p02573 | u181412342 | 1599163595 | Python | PyPy3 (7.3.0) | py | Runtime Error | 90 | 74724 | 1778 | import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import re... |
s432096533 | p02573 | u181412342 | 1599162864 | Python | PyPy3 (7.3.0) | py | Runtime Error | 474 | 191804 | 1820 | import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import re... |
s134117002 | p02573 | u181412342 | 1599162753 | Python | PyPy3 (7.3.0) | py | Runtime Error | 443 | 193396 | 1803 | import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import re... |
s721800892 | p02573 | u169165784 | 1599157839 | Python | Python (3.8.2) | py | Runtime Error | 1308 | 63452 | 1006 | import numpy
class UnionFind:
def __init__(self, N):
self.N = N
# the parent of all node is itself
# self.parent = list(range(N))
self.parent = [-1] * N
def root(self, i):
if self.parent[i] < 0:
return i
r = self.root(self.parent[i])
self.p... |
s748879033 | p02573 | u169165784 | 1599157572 | Python | Python (3.8.2) | py | Runtime Error | 1377 | 63456 | 1056 | import numpy
class UnionFind:
def __init__(self, N):
self.N = N
# the parent of all node is itself
# self.parent = list(range(N))
self.parent = [-1] * N
def root(self, i):
if self.parent[i] < 0:
return i
else:
r = self.root(self.parent[i... |
s192592542 | p02573 | u238084414 | 1599147310 | Python | Python (3.8.2) | py | Runtime Error | 537 | 16504 | 393 | def root(x):
if F[x] < 0:
return x
else:
F[x] = root(F[x])
return F[x]
def unite(x, y):
rx = root(x)
ry = root(y)
if rx == ry:
return
if rx > ry:
x, y = y, x
F[x] += F[y]
F[y] = x
N, M = map(int, input().split())
F = [-1] * N
for m in range(M):
a, b = map(int, input().split())
... |
s348713542 | p02573 | u845573105 | 1599146871 | Python | Python (3.8.2) | py | Runtime Error | 745 | 19800 | 476 | N, M = map(int, input().split())
r = [i for i in range(N+1)]
n = [0 for i in range(N+1)]
buf = []
def root(x):
if x==r[x]:
return x
else:
r[x] = root(r[x])
return r[x]
def unite(x, y):
rx = root(x)
ry = root(y)
if rx != ry:
r[ry] = rx
for _ in range(M):
a, b = map(int, input().split())
... |
s354998282 | p02573 | u196455939 | 1599144615 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2071 | 370876 | 672 | #D - Friends
N,M = map(int,input().split())
par = [i for i in range(N+1)]
rank = [1] * (N + 1)
def find(x):
if par[x] == x:
return x
else:
par[x] = find(par[x]) #経路圧縮
return par[x]
def size(x):
return par.count(find(x))
def unite(x,y):
x = find(x)
y = find(y)
if x == y... |
s064276018 | p02573 | u525571359 | 1599142840 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2213 | 231544 | 1479 | import sys
from io import StringIO
import unittest
def resolve():
N, M = map(int, input().split())
l = []
for _ in range(M):
i,j = map(int, input().split())
gi = find_group(l,i)
if not gi:
gi = {i}
l.append(gi)
gj = find_group(l, j)
if not gj:... |
s769425019 | p02573 | u433697974 | 1599142453 | Python | Python (3.8.2) | py | Runtime Error | 460 | 29840 | 556 | import sys
N, M = map(int, input().split())
if M == 0:
print(1)
sys.exit()
check = [0]*N
friendlist = []
tmp = 1
for i in range(M):
a, b = map(lambda x: int(x)-1, input().split())
if check[a] + check[b] == 0:
check[a] = tmp
check[b] = tmp
friendlist.append(set([a,b]))
tmp += 1
elif check[a... |
s077447492 | p02573 | u196455939 | 1599141940 | Python | Python (3.8.2) | py | Runtime Error | 2365 | 149472 | 648 | #D - Friends
N,M = map(int,input().split())
par = [i for i in range(N+1)]
def find(x):
if par[x] == x:
return x
else:
par[x] = find(par[x]) #経路圧縮
return par[x]
def size(x):
return par.count(find(x))
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return 0
... |
s634082649 | p02573 | u433697974 | 1599141855 | Python | Python (3.8.2) | py | Runtime Error | 483 | 29452 | 506 | N, M = map(int, input().split())
check = [0]*N
friendlist = []
tmp = 1
for i in range(M):
a, b = map(lambda x: int(x)-1, input().split())
if check[a] + check[b] == 0:
check[a] = tmp
check[b] = tmp
friendlist.append(set([a,b]))
tmp += 1
elif check[a] == 0:
friendlist[check[b]-1].add(a)
chec... |
s485679429 | p02573 | u377834804 | 1599119949 | Python | Python (3.8.2) | py | Runtime Error | 822 | 13852 | 679 | class UnionFind:
def __init__(self, N):
self.r = [-1]*(N+1)
def root(self, x):
if self.r[x] < 0:
return x
else:
self.r[x] = self.root(self.r[x])
return self.r[x]
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
else:
s... |
s903721526 | p02573 | u474202990 | 1599119288 | Python | PyPy3 (7.3.0) | py | Runtime Error | 95 | 80876 | 1154 | class unionfind():
def __init__(self,n):
#親番号<0なら根
#根の場合、数値の絶対値が要素数
self.par=[-1 for i in range(n)]
def root(self,x):
par=self.par
if par[x]<0:
return x
else:
self.root = self.root(par[x])
return self.root
... |
s295165338 | p02573 | u377834804 | 1599119201 | Python | Python (3.8.2) | py | Runtime Error | 835 | 14252 | 675 | class UnionFind:
def __init__(self, N):
self.r = [-1]*N
def root(self, x):
if self.r[x] < 0:
return x
else:
self.r[x] = self.root(self.r[x])
return self.r[x]
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
else:
self.... |
s568251205 | p02573 | u474202990 | 1599116391 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2207 | 87592 | 895 | class unionfind():
def __init__(self,n):
self.par=[i for i in range(n)]
def root(self,x):
#自分自身の番号==parの番号なら根
par=self.par
if par[x]==x:
return x
else:
self.root = self.root(par[x])
return self.root
def unite(self... |
s978391515 | p02573 | u148472503 | 1599091277 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 53472 | 702 | from collections import defaultdict
n,m = map(int, input().strip().split(" "))
adjList = defaultdict(list)
for i in range(m):
a,b = map(int, input().strip().split(" "))
a-=1
b-=1
if b not in adjList[a]:
adjList[a].append(b)
if a not in adjList[b]:
adjList[b].append(a)
... |
s498320556 | p02573 | u148472503 | 1599090984 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 53404 | 663 | from collections import defaultdict
n,m = map(int, input().strip().split(" "))
adjList = defaultdict(list)
for i in range(m):
a,b = map(int, input().strip().split(" "))
a-=1
b-=1
if b not in adjList[a]:
adjList[a].append(b)
if a not in adjList[b]:
adjList[b].append(a)
... |
s137264024 | p02573 | u531219227 | 1599090208 | Python | Python (3.8.2) | py | Runtime Error | 483 | 603832 | 470 | import sys
sys.setrecursionlimit(10**9)
N,M = map(int,input().split())
root = [i for i in range(N)]
def r(x):
if root[x] < 0:
return x
else:
root[x] = r(root[x])
return root[x]
def unite(x,y):
x = r(x)
y = r(y)
if x == y:
return
root[x] += root[y]
root[y] = x
def size(x):
x = r(x)
... |
s493668344 | p02573 | u279439669 | 1599088255 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 57860 | 799 | class UnionFind():
par = []
sizes = []
def __init__(self, N):
self.par = [i for i in range(N)]
self.sizes = [1 for _ in range(N)]
def root(self, x: int)-> int:
if (self.par[x] == x):
return x
return self.root(self.par[x])
def unite(self, x: int, y: int):
rootX = self.root(x)
r... |
s194961133 | p02573 | u279439669 | 1599087500 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 61276 | 771 | class UnionFind():
par = []
sizes = []
def __init__(self, N):
self.par = [i for i in range(N)]
self.sizes = [1 for _ in range(N)]
def root(self, x: int)-> int:
if (self.par[x] == x):
return x
return self.root(self.par[x])
def unite(self, x: int, y: int):
rootX = self.root(x)
r... |
s140714698 | p02573 | u148472503 | 1599087140 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 53248 | 653 | from collections import defaultdict
n,m = map(int, input().strip().split(" "))
adjList = defaultdict(list)
for i in range(m):
a,b = map(int, input().strip().split(" "))
if b not in adjList[a]:
adjList[a].append(b)
if a not in adjList[b]:
adjList[b].append(a)
mca = 0
visited... |
s049378590 | p02573 | u970267139 | 1599083893 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 17580 | 815 | class UnionFind():
def __init__(self, n):
self.par = [-1]*n
def root(self, x):
if self.par[x] < 0:
return x
return self.root(self.par[x])
def unite(self, x, y):
if x > y:
x, y = y, x
rx = self.root(x)
ry = self.root(y)
if rx !... |
s514857902 | p02573 | u970267139 | 1599083850 | Python | Python (3.8.2) | py | Runtime Error | 28 | 10600 | 808 | class UnionFind():
def __init__(self, n):
self.par = [-1]*n
def root(self, x):
if self.par[x] < 0:
return x
return self.root(self.par[x])
def unite(self, x, y):
if x > y:
x, y = y, x
rx = self.root(x)
ry = self.root(y)
if rx !... |
s882458646 | p02573 | u970267139 | 1599083496 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 54096 | 831 | n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
class UnionFind:
def __init__(self, n):
self.par = [-1]*n
def root(self, x):
if self.par[x] < 0:
return x
return self.root(self.par[x])
def unite(self, x, y):
if x > y:
... |
s752365142 | p02573 | u957098479 | 1599081883 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 11268 | 681 | import collections
#=input()
#=int(input())
n,m=map(int,input().split())
#=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]
def rep(l, x, y):
for i in range(n + 1):
if l[i] == x:
l[i] = y
l = [0] * (n + 1)
for i in range(1, m + 1):
a,b = map(int,input().s... |
s963085823 | p02573 | u707316131 | 1599076425 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2210 | 172268 | 1274 | def dfs(visited, graph, node):
if node not in visited:
visited.append(node)
for neighbour in graph[node]:
dfs(visited, graph, neighbour)
def insert_adj_list(graph,f,t):
if (t not in graph[f]):
graph[f].append(t)
if (f not in graph[t]):
graph[t].append(f)
def i... |
s276249206 | p02573 | u707316131 | 1599076250 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2208 | 172336 | 1269 | def dfs(visited, graph, node):
if node not in visited:
visited[node]=1
for neighbour in graph[node]:
dfs(visited, graph, neighbour)
def insert_adj_list(graph,f,t):
if (t not in graph[f]):
graph[f].append(t)
if (f not in graph[t]):
graph[t].append(f)
def init_d... |
s920252866 | p02573 | u940780117 | 1599073622 | Python | Python (3.8.2) | py | Runtime Error | 672 | 32040 | 506 | N,Q=map(int,input().split())
par=[i for i in range(N+1)]
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 in range... |
s080019123 | p02573 | u182509599 | 1599070870 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 51072 | 965 | """
https://atcoder.jp/contests/abc177/tasks/abc177_d
"""
def solve(n, m, a):
grp = []
for f in a:
if len(grp) == 0:
grp.append(set(f))
else:
u = False
for gi, g in enumerate(grp):
if f[0] in g or f[1] in g:
grp[gi] = ... |
s295527461 | p02573 | u699636103 | 1599055384 | Python | PyPy3 (7.3.0) | py | Runtime Error | 476 | 81872 | 809 | class disjoint:
def __init__(self, x: int):
self.a = [-1] * x
def root(self, x: int):
if self.a[x] < 0:
return x
self.a[x] = self.root(self.a[x])
return self.a[x]
def unite(self, x: int, y: int):
x, y = self.root(x), self.root(y)
if x == y:
... |
s559866393 | p02573 | u614381513 | 1599050417 | Python | Python (3.8.2) | py | Runtime Error | 992 | 58688 | 461 | from statistics import mode
n, m = map(int, input().split())
rels = [i for i in range(n + 1)]
inf = []
count = [0] * n
for i in range(m):
rel = list(map(int, input().split()))
rel = sorted(rel)
inf.append(rel)
inf = sorted(inf)
for rel in inf:
a = rel[0] - 1
b = rel[1] - 1
rels[b] = rels[a]... |
s888759678 | p02573 | u614381513 | 1599038536 | Python | Python (3.8.2) | py | Runtime Error | 76 | 33692 | 335 | from statistics import mode
n, m = map(int, input().split())
rels = [i for i in range(n)]
#count = [0] * n
#print(count)
for i in range(m):
rel = list(map(int, input().split()))
rel = sorted(rel)
a = rel[0] - 1
b = rel[1] - 1
rels[b] = rels[a]
count[a] = count[a] + 1
#print(count)
pr... |
s355906088 | p02573 | u698902360 | 1599037924 | Python | Python (3.8.2) | py | Runtime Error | 812 | 50948 | 775 | import sys
from collections import defaultdict
import collections
class UnionFindPathCompression():
def __init__(self, n):
self.parents = list(range(n))
def find(self, x):
if self.parents[x] == x:
return x
else:
self.parents[x] = self.find(self.parents[x])
... |
s872950683 | p02573 | u970267139 | 1598999018 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 68664 | 844 | n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
class UnionFind:
par = []
def __init__(self, n):
for i in range(n):
self.par.append(i)
def root(self, x):
if self.par[x] == x:
return x
return self.root(self.par[x])
... |
s092059873 | p02573 | u699636103 | 1598994641 | Python | PyPy3 (7.3.0) | py | Runtime Error | 499 | 86872 | 821 | class disjoint:
def __init__(self, x: int):
self.a = [-1 for i in range(x)]
def root(self, x: int):
if self.a[x] < 0:
return x
self.a[x] = self.root(self.a[x])
return self.a[x]
def unite(self, x: int, y: int):
x, y = self.root(x), self.root(y)
if... |
s121363456 | p02573 | u124864167 | 1598992938 | Python | Python (3.8.2) | py | Runtime Error | 1705 | 309624 | 108 | from networkx import*;_,*n=map(str.split,open(0));print(max(map(len,[*connected_components(Graph(n))]),1,1)) |
s525044624 | p02573 | u699636103 | 1598992094 | Python | PyPy3 (7.3.0) | py | Runtime Error | 490 | 114540 | 457 | n, m = [int(i) for i in input().split()]
graph = [[] for i in range(n)]
for _ in range(m):
x, y = [int(i) for i in input().split()]
x -= 1
y -= 1
graph[x].append(y)
graph[y].append(x)
vis = [False] * n
def dfs(x):
vis[x] = False
count = 1
for i in graph[x]:
if not vis[i]:
... |
s572200549 | p02573 | u699636103 | 1598990656 | Python | Python (3.8.2) | py | Runtime Error | 714 | 44664 | 492 | n, m = [int(i) for i in input().split()]
graph = [[] for i in range(n)]
for _ in range(m):
x, y = [int(i) for i in input().split()]
x -= 1
y -= 1
graph[x].append(y)
graph[y].append(x)
vis = [False] * n
def dfs(x: int):
count = 1
for i in graph[x]:
if not vis[i]:
vis[i... |
s151741154 | p02573 | u699636103 | 1598990459 | Python | Python (3.8.2) | py | Runtime Error | 741 | 44512 | 494 | n, m = [int(i) for i in input().split()]
graph = [[] for i in range(n)]
for _ in range(m):
x, y = [int(i) for i in input().split()]
x -= 1
y -= 1
graph[x].append(y)
graph[y].append(x)
vis = [False] * n
def dfs(x):
count = 1
for i in graph[x]:
if vis[i] == False:
vis[i]... |
s638141378 | p02573 | u570155187 | 1598984913 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 62936 | 767 | from collections import Counter
n,m = map(int,input().split())
ab = list(list(map(int,input().split())) for _ in range(m))
a,b = [list(i) for i in zip(*ab)]
group = [-1]*(n+1)
group_name = 0
for i in range(m):
if group[a[i]] == -1 and group[b[i]] == -1:
group[a[i]] = group_name
group[b[i]] = group_name
... |
s684511378 | p02573 | u200887663 | 1598984089 | Python | Python (3.8.2) | py | Runtime Error | 1101 | 104988 | 1055 | #n = int(input())
import random
n, m = map(int, input().split())
#al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
adjl = [[] for _ in range(n+1)]
NIL = -1
appear = {}
isalone = {}
for i in range(m):
a, b = map(int, input().split())
if appear.get((a, b), False) or app... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.