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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s465152672 | p02536 | u722868069 | 1601184461 | Python | Python (3.8.2) | py | Runtime Error | 422 | 36564 | 775 | def root(x):
if r[x] < 0:
return x
else:
r[x] = root(r[x])
return r[x]
from operator import itemgetter
n, m = map(int, input().split())
road = [list(map(int,input().split())) for i in range(m)]
r = [-1]*(n+1)
#print(g)
road = sorted(road, key=lambda x:(x[0], x[1]))
#print(r)
group_num = 1;
for i, ... |
s163617802 | p02536 | u979823197 | 1601182745 | Python | PyPy3 (7.3.0) | py | Runtime Error | 280 | 78776 | 1311 | 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 = ... |
s501610021 | p02536 | u234454594 | 1601181817 | Python | PyPy3 (7.3.0) | py | Runtime Error | 84 | 68768 | 417 | from collections import deque
n,m=map(int,input().split())
road=[[] for i i range(n)]
flag=[0]*n
for i in range(m):
a,b=map(int,input().split())
road[a-1].append(b-1)
road[b-1].append(a-1)
count=0
for i in range(n):
if flag[i]!=0:
continue
count+=1
q=[k]
while q:
p=q.popleft(... |
s178609934 | p02536 | u910358825 | 1601179151 | Python | Python (3.8.2) | py | Runtime Error | 28 | 9892 | 543 | n,m=map(int, input().split())
lst=[list(map(int, input().split()))]
town=[1]*n
for j in range(2):
town[lst[0][j]-1]=0
l=1
for i in range(m-1):
a=list(map(int, input().split()))
for j in range(2):
town[a[j]-1]=0
cnt=0
for k in range(l):
if (a[0] or a[1]) in lst[k]:
lst... |
s900089433 | p02536 | u865383026 | 1601179043 | Python | Python (3.8.2) | py | Runtime Error | 55 | 11968 | 559 | N, M = map(int, input().split())
L = [0] * N
D = {}
c = 1
for i in range(M):
A, B = map(int, input().split())
if L[A - 1] == L[B - 1] == 0:
D[c] = set()
D[c].add(A)
D[c].add(B)
L[A - 1] = c
L[B - 1] = c
c += 1
elif L[A - 1] == 0:
D[L[B - 1]].add(A)
L[A - 1] = L[B - 1]
elif L[B - ... |
s595475583 | p02536 | u363391958 | 1601178739 | Python | Python (3.8.2) | py | Runtime Error | 311 | 31752 | 551 | def main(dic, lst):
seen = set()
res = 0
def bfs(i):
if i in seen:
return
seen.add(i)
for j in dic[i]:
bfs(j)
for i in lst:
if i in seen:
continue
bfs(i)
res += 1
return res - 1
n, m = tuple(map(int, input().sp... |
s021823789 | p02536 | u865383026 | 1601178709 | Python | Python (3.8.2) | py | Runtime Error | 49 | 12000 | 533 | N, M = map(int, input().split())
L = [0] * N
D = {}
c = 1
for i in range(M):
A, B = map(int, input().split())
if L[A - 1] == 0 and L[B - 1] == 0:
D[c] = set()
D[c].add(A)
D[c].add(B)
L[A - 1] = c
L[B - 1] = c
c += 1
elif L[A - 1] == 0:
D[L[B - 1]].add(A)
L[A - 1] = L[B - 1]
elif ... |
s016695518 | p02536 | u478417863 | 1601177092 | Python | Python (3.8.2) | py | Runtime Error | 202 | 12876 | 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 = ... |
s259943230 | p02536 | u456225659 | 1601177079 | Python | Python (3.8.2) | py | Runtime Error | 364 | 29412 | 861 | from collections import defaultdict
class graph:
def __init__(self,V):
self.V=V
self.graph=defaultdict(list)
def dfs(self,temp,v,visited):
visited[v]=True
temp.append(v)
for i in self.graph[v]:
if visited[i]==False:
temp=self.dfs(temp,i,visite... |
s811943715 | p02536 | u456225659 | 1601176900 | Python | Python (3.8.2) | py | Runtime Error | 358 | 29228 | 859 | from collections import defaultdict
class graph:
def __init__(self,V):
self.V=V
self.graph=defaultdict(list)
def dfs(self,temp,v,visited):
visited[v]=True
temp.append(v)
for i in self.graph[v]:
if visited[i]==False:
temp=self.dfs(temp,i,visite... |
s759314978 | p02536 | u881675205 | 1601176767 | Python | PyPy3 (7.3.0) | py | Runtime Error | 313 | 105652 | 453 | def s(way):
global w
global c
for i in way:
if c[i] == 0:
c[i] = 1
s(w[i])
from collections import deque
d = deque()
n,m = map(int,input().split())
w = [[] for i in range(n)]
c = [0 for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
w[a-1].append(... |
s986519326 | p02536 | u881675205 | 1601176679 | Python | PyPy3 (7.3.0) | py | Runtime Error | 313 | 105804 | 441 | def s(way):
global w
for i in way:
if c[i] == 0:
c[i] = 1
s(w[i])
from collections import deque
d = deque()
n,m = map(int,input().split())
w = [[] for i in range(n)]
c = [0 for i in range(n)]
for i in range(m):
a,b = map(int,input().split())
w[a-1].append(b-1)
w[b... |
s543135893 | p02536 | u881675205 | 1601176536 | Python | PyPy3 (7.3.0) | py | Runtime Error | 361 | 110212 | 537 | def s(way):
global w
for i in way:
if c[i] == 0:
c[i] = 1
s(w[i])
from collections import deque
d = deque()
n,m = map(int,input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
w = [[] for i in range(n)]
wc = [0 for i in range(n)]
c = [0 for i in range(n)]
for i ... |
s292941519 | p02536 | u602773379 | 1601176532 | Python | Python (3.8.2) | py | Runtime Error | 216 | 27288 | 354 | #入力:N,M(int:整数)
def input2():
return map(int,input().split())
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
return list(map(int,input().split()))
n,m=input2()
AB=[input_array() for _ in range(m)]
uf = UnionFind(n)
for ab in AB:
a=ab[0]
b=ab[1]
uf.union(a-1,b-1)
ans=0
for i in uf.parents:
if i < 0:
ans+=... |
s557407441 | p02536 | u456225659 | 1601176429 | Python | Python (3.8.2) | py | Runtime Error | 364 | 29228 | 857 | from collections import defaultdict
class graph:
def __init__(self,V):
self.V=V
self.graph=defaultdict(list)
def dfs(self,temp,v,visited):
visited[v]=True
temp.append(v)
for i in self.graph[v]:
if visited[i]==False:
temp=self.dfs(temp,i,visite... |
s208469706 | p02536 | u845573105 | 1601176391 | Python | PyPy3 (7.3.0) | py | Runtime Error | 153 | 68196 | 730 | class UnionFind:
def __init__(self, n):
self.class = [i for i in range(n)]
self.n = n
def whichclass(self, x):
if self.class[x]==x:
return x
else:
self.class[x] = self.whichclass(self.class[x])
return self.class[x]
def union(self, x, y):
cx = self.whichclass(x)
cy = self.... |
s969203150 | p02536 | u479638406 | 1601174872 | Python | Python (3.8.2) | py | Runtime Error | 289 | 22764 | 436 | n, m = map(int, input().split())
l = []
for _ in range(m):
a, b = map(int, input().split())
l.append((a, b))
l.sort()
a =[[l[0][0],l[0][1]]]
cnt = 0
num = 1
for i in range(1, m):
if l[i][0] in a[cnt] and l[i][1] not in a[cnt]:
a[cnt].append(l[i][1])
num += 1
elif l[i][1] in a[cnt] and l... |
s533934356 | p02536 | u243714267 | 1601174678 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9072 | 1594 | class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
# ノードxのrootノードを見つける
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
... |
s228063895 | p02536 | u813993459 | 1601174623 | Python | Python (3.8.2) | py | Runtime Error | 352 | 46752 | 331 | import numpy as np
n, m =list(map(int,input().split()))
x=np.array([list(map(int,input().split())) for i in range(m)])
data=x
ans=0
add_times = len(np.arange(1,n+1))-len(np.unique(np.array(x)))
while(1):
if len(data)==0:
break
num=[data[0][0]]
data =check_cl(data,num)
ans+=1
print(int(ans-1+... |
s854802261 | p02536 | u615285493 | 1601174613 | Python | PyPy3 (7.3.0) | py | Runtime Error | 202 | 74708 | 2441 | import os
import sys
from io import BytesIO, IOBase
def main():
# sys.setrecursionlimit(10**6)
n, m = getints()
g = [-1] * n
def find(u):
if g[u] < 0:
return u
else:
g[u] = find(u)
return g[u]
def merge(u, v):
u = find(u)
v = fin... |
s698272468 | p02536 | u318427318 | 1601174407 | Python | Python (3.8.2) | py | Runtime Error | 129 | 27272 | 350 | #-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
def main():
roads=[]
n,m = map(int,input().split())
roads=[list(map(int,input().split())) for _ in range(m)]
count=0
for i in range(1,n+1):
if roads in i:
continue
else:
count+=1
print(count)
if __... |
s896371061 | p02536 | u463945054 | 1601174394 | Python | Python (3.8.2) | py | Runtime Error | 199 | 9028 | 223 | N,M = map(int,input().split())
count = 0
t = 1
for t in range(N):
A,B = map(int,input().split())
if t == A or t == B:
count += 0
else:
count += 1
print(count) |
s333336421 | p02536 | u750058957 | 1601174377 | Python | Python (3.8.2) | py | Runtime Error | 306 | 23064 | 1538 | 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 = ... |
s566868458 | p02536 | u320681122 | 1601174349 | Python | Python (3.8.2) | py | Runtime Error | 145 | 15308 | 482 | from math import factorial
def main():
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * n
for i in range(m):
a[i], b[i] = map(int, input().split())
c[a[i]] = 1
c[b[i]] = 1
sum = factorial(n) / 2 * factorial(n - 2)
if sum <= m:
print... |
s058082114 | p02536 | u352198227 | 1601174336 | Python | Python (3.8.2) | py | Runtime Error | 240 | 25252 | 1117 | a = list(map(int,input().split()))
N = a[0]
M = a[1]
cities = [0] * N
roads = []
lands = {}
for i in range(M):
a = list(map(int,input().split()))
roads.append([a[0], a[1]])
for r in roads:
#print(cities)
#print(lands)
if cities[r[0]-1] == 0:
cities[r[0]-1] = r[0]
lands[cities[r[0... |
s414383781 | p02536 | u950754160 | 1601174335 | Python | PyPy3 (7.3.0) | py | Runtime Error | 259 | 86684 | 633 | x,y=map(int,input().split())
a=[list(map(int,input().split())) for l in range(y)]
M=0
c=0
t=[]
g=[]
g.append(a[0][0])
g.append(a[1][0])
while M<y-1:
if not a[0][M] in t:
t.append(a[0][M])
if not a[1][M] in t:
t.append(a[1][M])
c=c+3
if a[0][M] in t:
i... |
s445064529 | p02536 | u648868410 | 1601174324 | Python | Python (3.8.2) | py | Runtime Error | 230 | 11024 | 1465 |
import sys
sys.setrecursionlimit(10000)
class UnionFindTree:
def __init__(self,size):
"""
size個の集合を作成
負の値は、ルートで集合の個数
正の値は、次の要素
"""
self.table=[-1 for _ in range(size)]
def find(self,x):
"""
グループ番号を取得
"""
# 本質的には、木を上に辿るだけ
# ただし、通常、UnionFindでは経路圧縮を行うのが普通らしい
if self.table[x] < 0:
# 一個上がルートな... |
s507052760 | p02536 | u266675845 | 1601174314 | Python | Python (3.8.2) | py | Runtime Error | 270 | 17652 | 1384 | 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 = ... |
s921000930 | p02536 | u306241759 | 1601174282 | Python | PyPy3 (7.3.0) | py | Runtime Error | 324 | 127020 | 814 | def dfs(now_node):
seen[now_node] = True
connect_nodes = graph[now_node]
for node in connect_nodes:
if seen[node] == True:#探索済みだったらスルー
continue
dfs(node)
N, M = map(int, input().split())
#edges = [list(map(int, input().split())) for i in range(M)]
edges = []
for i in range(M):
... |
s715647099 | p02536 | u210545407 | 1601174277 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 30804 | 695 | N, M=map(int, input().split(" "))
graph=[[] for i in range(N)]
for i in range(M):
temp=list(map(lambda x: x-1, map(int, input().split(" "))))
graph[temp[0]].append(temp[1])
graph[temp[1]].append(temp[0])
# print(graph)
seen=[False for i in range(N)]
todo=[]
def seek(graph, current):
seen[current]=True
for ... |
s140691275 | p02536 | u609258687 | 1601174233 | Python | PyPy3 (7.3.0) | py | Runtime Error | 268 | 91164 | 690 | n,m = map(int, input().split())
brdg = []
for _ in range(m):
brdg.append(list(map(int, input().split())))
# 島つくる
for i in range(m):
for j in range(i+1,m):
if brdg[i][0] in brdg[j]:
brdg.append(list(set(brdg[i]+brdg[j])))
brdg.remove(brdg[i])
brdg.remove(brdg[j])
... |
s675110527 | p02536 | u210545407 | 1601174229 | Python | Python (3.8.2) | py | Runtime Error | 3952 | 148964 | 685 | N, M=map(int, input().split(" "))
graph=[[] for i in range(N)]
for i in range(M):
temp=list(map(lambda x: x-1, map(int, input().split(" "))))
graph[temp[0]].append(temp[1])
graph[temp[1]].append(temp[0])
print(graph)
seen=[False for i in range(N)]
todo=[]
def seek(graph, current):
seen[current]=True
for ci... |
s674967214 | p02536 | u473172054 | 1601174201 | Python | Python (3.8.2) | py | Runtime Error | 207 | 19560 | 348 | n, m = map(int, input().split())
par = [i for i in range(n)]
connection = [i for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
cur = connection[b]
connection[b] = connection[a]
par[cur] = par[a]
for i in range(n):
num = connection[i]
connection[i] = par[num]
ans = len(set(... |
s887052932 | p02536 | u252828980 | 1601174178 | Python | Python (3.8.2) | py | Runtime Error | 200 | 10668 | 918 | n,m = map(int,input().split())
#L = [list(map(int,input().split())) for i in range(m)]
class Unionfind:
def __init__(self,n):
self.uf = [-1]*n
def find(self,x):
if self.uf[x] < 0:
return x
else:
self.uf[x] = self.find(self.uf[x])
return self.... |
s694255985 | p02536 | u359641414 | 1601174169 | Python | Python (3.8.2) | py | Runtime Error | 217 | 16828 | 472 | n, m = map(int, input().split())
a = []
b = []
for i in range(m):
inp = list(map(int,input().split()))
a.append(inp[0])
b.append(inp[1])
f = [[]]
cnt=0
for i in range(m):
flg=0
for j in range(cnt):
if a[i] in f[j]:
f[j].append(b[i])
flg = 1
elif b[i] in f[j]... |
s911153317 | p02536 | u912330011 | 1601174166 | Python | Python (3.8.2) | py | Runtime Error | 367 | 9572 | 709 | N, M = map(int, input().split())
rootedPoints = set()
points = []
for _ in range(M):
A, B = map(int, input().split())
A -= 1
B -= 1
rootedPoints.add(A)
rootedPoints.add(B)
Aindex = False
Bindex = False
for i, ps in enumerate(points):
if A in ps: Aindex = i
if B in ps: Bindex = i
if Aindex ... |
s044400066 | p02536 | u352198227 | 1601174154 | Python | Python (3.8.2) | py | Runtime Error | 236 | 24844 | 1097 | a = list(map(int,input().split()))
N = a[0]
M = a[1]
cities = [0] * N
roads = []
lands = {}
for i in range(M):
a = list(map(int,input().split()))
roads.append([a[0], a[1]])
for r in roads:
#print(cities)
#print(lands)
if cities[r[0]-1] == 0:
cities[r[0]-1] = r[0]
lands[r[0]] = [r... |
s561337806 | p02536 | u609258687 | 1601174147 | Python | PyPy3 (7.3.0) | py | Runtime Error | 253 | 86972 | 684 | n,m = map(int, input().split())
brdg = []
for _ in range(m):
brdg.append(list(map(int, input().split())))
# 島つくる
for i in range(m):
for j in range(i+1,m):
if brdg[i][0] in brdg[j]:
brdg.append(list(set(brdg[i]+brdg[j])))
brdg.remove(brdg[i])
brdg.remove(brdg[j])
... |
s971624920 | p02536 | u266675845 | 1601174145 | Python | Python (3.8.2) | py | Runtime Error | 272 | 17744 | 1402 | N, M = map(int, input().split())
A = [0 for _ in range(M)]
B = [0 for _ in range(M)]
S = set()
for i in range(M):
A[i] , B[i] = 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:
... |
s110446094 | p02536 | u310337637 | 1601174132 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 62676 | 2369 | n, m = map(int, input().split())
ab = [map(int, input().split()) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
can_stay = []
branch_stay = []
can_flag_a = 0
can_flag_b = 0
branch_node = 0
need_road = 0
can_stay.append(a[0])
can_stay.append(b[0])
for road in range(1, m):
can_flag_a = 0
can_flag_b = 0... |
s638200803 | p02536 | u491916915 | 1601174120 | Python | Python (3.8.2) | py | Runtime Error | 27 | 8980 | 206 | c, r = input("").split(" ")
cityOne, cityTwo = input("").split(" ")
c, r, cityOne, cityTwo = int(c), int(r), int(cityOne), int(cityTwo)
nr = 0
if r %2==0 and != c - 1:
nr += 1
else:
nr+=2
print(nr) |
s638129350 | p02536 | u912330011 | 1601174112 | Python | Python (3.8.2) | py | Runtime Error | 304 | 9736 | 691 | N, M = map(int, input().split())
rootedPoints = set()
points = []
for _ in range(M):
A, B = map(int, input().split())
rootedPoints.add(A)
rootedPoints.add(B)
Aindex = False
Bindex = False
for i, ps in enumerate(points):
if A in ps: Aindex = i
if B in ps: Bindex = i
if Aindex is not False and B... |
s749943408 | p02536 | u320681122 | 1601174077 | Python | Python (3.8.2) | py | Runtime Error | 197 | 17584 | 384 | def main():
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
for i in range(m):
a[i], b[i] = map(int, input().split())
c = [0] * n
for i in range(m):
c[a[i]] = 1
c[b[i]] = 1
count = 0
for i in range(n):
if c[i] == 0:
count +... |
s532902522 | p02536 | u894856270 | 1601174055 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2207 | 73320 | 310 | N, M = input().split()
N = int(N)
M = int(M)
l = []
l2 = []
for i in range(N):
l.append(i)
for i in range(M):
A, B = input().split()
A = int(A)
B = int(B)
if A in l:
pass
else:
l2.append(l.pop(int(A) - 1))
if B in l:
pass
else:
l2.append(l.pop(int(B) - 1))
print(N - len(l) + 1) |
s661308310 | p02536 | u364741711 | 1601174036 | Python | Python (3.8.2) | py | Runtime Error | 25 | 9216 | 185 | n,m = map(int,input().split())
cl_c=[]
ans = 0
for i in range(m) :
a,b = map(int,input().split())
cl_c.append(a,b)
if a != 1 :
ans += 1
set(cl_c)
print(n-len(cl_c)+ans) |
s239061132 | p02536 | u319245933 | 1601174014 | Python | Python (3.8.2) | py | Runtime Error | 326 | 19392 | 409 | N,M = map(int, input().split())
seen = [False] * N
def dfs(G, v):
global seen
seen[v] = True
for n_v in G[v]:
if seen[n_v]:
continue
dfs(G, n_v)
G = [[]] * N
for _ in range(M):
a,b = map(int, input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
count = 0
for v i... |
s149406753 | p02536 | u415581265 | 1601173998 | Python | Python (3.8.2) | py | Runtime Error | 3070 | 139864 | 204 | n, m = [int(s) for s in input().split(' ')]
c = [False] * n
for i in range(m):
node = input().split(' ')
for j in range(2):
c[int(node[j]) - 1] = True
print(c)
print(c.count(False)) |
s709817706 | p02536 | u473172054 | 1601173989 | Python | Python (3.8.2) | py | Runtime Error | 203 | 19272 | 369 | n, m = map(int, input().split())
par = [i for i in range(n)]
connection = [i for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
cur = connection[b]
connection[b] = connection[a]
if par[cur] != a:
par[cur] = a
for i in range(n):
num = connection[i]
connection[i] = pa... |
s811554798 | p02536 | u210545407 | 1601173962 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 30732 | 592 | N, M=map(int, input().split(" "))
graph=[[] for i in range(N)]
for i in range(M):
temp=list(map(lambda x: x-1, map(int, input().split(" "))))
graph[temp[0]].append(temp[1])
graph[temp[1]].append(temp[0])
seen=[False for i in range(N)]
todo=[]
def seek(graph, current):
seen[current]=True
for city in graph[c... |
s465826031 | p02536 | u635252313 | 1601173952 | Python | Python (3.8.2) | py | Runtime Error | 203 | 12892 | 1376 | 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, ... |
s688154606 | p02536 | u491916915 | 1601173918 | Python | Python (3.8.2) | py | Runtime Error | 27 | 9012 | 206 | c, r = input("").split(" ")
cityOne, cityTwo = input("").split(" ")
c, r, cityOne, cityTwo = int(c), int(r), int(cityOne), int(cityTwo)
nr = 0
if r %2!=0 and != c - 1:
nr += 1
else:
nr+=2
print(nr) |
s521422533 | p02536 | u320681122 | 1601173892 | Python | Python (3.8.2) | py | Runtime Error | 187 | 17576 | 501 | from math import factorial
def main():
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
for i in range(m):
a[i], b[i] = map(int, input().split())
c = [0] * n
for i in range(m):
c[a[i]] = 1
c[b[i]] = 1
sum = factorial(n) / 2 * factorial(n - 2)
if sum ... |
s732402993 | p02536 | u415581265 | 1601173857 | Python | Python (3.8.2) | py | Runtime Error | 5702 | 139852 | 225 | n, m = [int(s) for s in input().split(' ')]
c = [False] * n
print(c)
for i in range(m):
node = input().split(' ')
for j in range(2):
c[int(node[j]) - 1] = True
print(c)
print(c)
print(c.count(False))
|
s432847761 | p02536 | u750058957 | 1601173856 | Python | Python (3.8.2) | py | Runtime Error | 313 | 39216 | 528 | N,M = map(int, input().split())
G = [[] for i in range(N)]
for v in range(M):
for w, c in enumerate(map(lambda x: int(x)-1, input().split())):
if c != -1:
G[v].append((w, c))
from heapq import heappush, heappop, heapify
used = [0]*N
que = [(c, w) for w, c in G[0]]
used[0] = 1
heapify(que)
ans... |
s581519334 | p02536 | u881675205 | 1601173850 | Python | PyPy3 (7.3.0) | py | Runtime Error | 381 | 107732 | 627 | def s(way):
global w
global wc
for i in way:
c[i] = 1
if wc[i] == 0:
wc[i] =1
for j in w[i]:
c[j]=1
for j in w[i]:
s(w[j])
n,m = map(int,input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
w = [[] for i i... |
s247066658 | p02536 | u912330011 | 1601173836 | Python | Python (3.8.2) | py | Runtime Error | 1261 | 32156 | 632 | N, M = map(int, input().split())
rootedPoints = set()
points = []
for _ in range(M):
A, B = map(int, input().split())
rootedPoints.add(A)
rootedPoints.add(B)
Aindex = False
Bindex = False
for i, ps in enumerate(points):
if A in ps: Aindex = i
if B in ps: Bindex = i
if Aindex is False and Bindex ... |
s323906526 | p02536 | u352198227 | 1601173798 | Python | Python (3.8.2) | py | Runtime Error | 246 | 24836 | 1051 | a = list(map(int,input().split()))
N = a[0]
M = a[1]
cities = [0] * N
roads = []
lands = {}
for i in range(M):
a = list(map(int,input().split()))
roads.append([a[0], a[1]])
for r in roads:
#print(cities)
#print(lands)
if cities[r[0]-1] == 0:
cities[r[0]-1] = r[0]
lands[r[0]] = [r... |
s415571909 | p02536 | u016843859 | 1601173787 | Python | Python (3.8.2) | py | Runtime Error | 468 | 44684 | 412 | from collections import defaultdict
N,M=map(int,input().split())
AB=list()
memo=[False]*N
G=defaultdict(set)
def dfs(i):
memo[i]=True
for j in G[i]:
if memo[j]==False:
dfs(j)
count=0
for i in range(M):
AB=list(map(int,input().split()))
G[AB[1]-1].add(AB[0]-1)
G[AB[0]-1].add(AB[1]... |
s942244699 | p02536 | u006728642 | 1601173786 | Python | Python (3.8.2) | py | Runtime Error | 231 | 31652 | 680 | N,M = map(int,input().split())
cityList = set()
loadList = []
for i in range(M):
loadList.append(set(list(map(int,input().split()))))
if(i >= 1):
if(len(loadList[0] & loadList[i]) != 0):
loadList[0] = loadList[0] | loadList[i]
del loadList[i]
for i in range(N):
cityList.add(i... |
s114650136 | p02536 | u491916915 | 1601173781 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9192 | 173 | c, r = input("").split(" ")
cityOne, cityTwo = input("").split(" ")
c, r, cityOne, cityTwo = int(c), int(r), int(cityOne), int(cityTwo)
nr=0
if r!=i-1:
nr+=1
print(nr) |
s991690769 | p02536 | u944396627 | 1601173772 | Python | Python (3.8.2) | py | Runtime Error | 557 | 36276 | 1115 | class UnionFind:
pairs = {}
def __init__(self, n):
for i in range(n):
self.pairs[i] = i
def set(self, s, t):
if s in self.pairs and self.pairs[s] == s:
self.pairs[s] = t
else:
self.pairs[t] = s
def root(self, x):
if self.pairs[x] == x... |
s378740769 | p02536 | u674588203 | 1601173757 | Python | Python (3.8.2) | py | Runtime Error | 202 | 13028 | 1358 | 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):
... |
s013614359 | p02536 | u959139907 | 1601173739 | Python | PyPy3 (7.3.0) | py | Runtime Error | 415 | 85188 | 2168 | # 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... |
s291559447 | p02536 | u912330011 | 1601173706 | Python | Python (3.8.2) | py | Runtime Error | 325 | 9656 | 629 | N, M = map(int, input().split())
rootedPoints = set()
points = []
for _ in range(M):
A, B = map(int, input().split())
rootedPoints.add(A)
rootedPoints.add(B)
Aindex = False
Bindex = False
for i, ps in enumerate(points):
if A in ps: Aindex = i
if B in ps: Bindex = i
if Aindex is False and Bindex ... |
s387785406 | p02536 | u753971348 | 1601173700 | Python | Python (3.8.2) | py | Runtime Error | 903 | 12828 | 426 | n, m = map(int,input().split())
allone = list(range(1,n+1))
paths = []
for l in range(m):
tempa,tempb = map(int,input().split())
paths.append([tempa,tempb])
allone.remove(tempa)
allone.remove(tempb)
cou = 0
if allone:
for r in allone:
su = False
for o in paths:
if r == o[0] or r == o[1]:
... |
s183486329 | p02536 | u881675205 | 1601173644 | Python | PyPy3 (7.3.0) | py | Runtime Error | 398 | 118356 | 600 | def s(way):
global w
global wc
for i in way:
c[i] = 1
if wc[i] == 0:
wc[i] =1
for j in w[i]:
c[j]=1
s(w[j])
n,m = map(int,input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
w = [[] for i in range(n)]
wc = [0 for i i... |
s010245931 | p02536 | u753971348 | 1601173638 | Python | Python (3.8.2) | py | Runtime Error | 803 | 12648 | 378 | n, m = map(int,input().split())
allone = list(range(1,n+1))
paths = []
for l in range(m):
tempa,tempb = map(int,input().split())
paths.append([tempa,tempb])
allone.remove(tempa)
allone.remove(tempb)
cou = 0
for r in allone:
su = False
for o in paths:
if r == o[0] or r == o[1]:
continue
else:
... |
s973657251 | p02536 | u125799132 | 1601173609 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 13676 | 727 | # C
[N, M] = [int(k) for k in input().split()]
dic = {}
L = []
for j in range(M):
[A, B] = [int(i) for i in input().split()]
if A in dic:
if B in dic:
L.pop(dic[B])
for m in dic:
if dic[m] == dic[B]:
dic[m] = dic[A]
else:
L... |
s226038842 | p02536 | u958820283 | 1601173593 | Python | Python (3.8.2) | py | Runtime Error | 299 | 27788 | 390 | n,m = map(int,input().split())
road=[[] for i in range(n)]
for i in range(m):
a,b= map(int,input().split())
road[a-1].append(b-1)
road[b-1].append(a-1)
d=[-1]*n
d[0]=1
f=[-1]*n
count=1
def dfs(src):
d[src]=count
for dst in road[src]:
if d[dst]==-1:
dfs(dst)
for root in range(n):... |
s110180050 | p02536 | u216728327 | 1601173589 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2207 | 73248 | 175 | N,M = map(int, input().split())
c = []
for i in range(N):
A,B = map(int, input().split())
if A not in c:
c.append(A)
if B not in c:
c.append(B)
print(N - len(c)) |
s467138592 | p02536 | u319245933 | 1601173582 | Python | Python (3.8.2) | py | Runtime Error | 325 | 19304 | 392 | N,M = map(int, input().split())
def dfs(G, v):
seen[v] = True
for n_v in G[v]:
if seen[n_v]:
continue
dfs(G, n_v)
seen = [False] * N
G = [[]] * N
for _ in range(M):
a,b = map(int, input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
count = 0
for v in range(N):
i... |
s560222301 | p02536 | u352198227 | 1601173572 | Python | Python (3.8.2) | py | Runtime Error | 244 | 24984 | 1022 | a = list(map(int,input().split()))
N = a[0]
M = a[1]
cities = [0] * N
roads = []
lands = {}
for i in range(M):
a = list(map(int,input().split()))
roads.append([a[0], a[1]])
for r in roads:
#print(cities)
#print(lands)
if cities[r[0]-1] == 0:
cities[r[0]-1] = r[0]
lands[r[0]] = [r... |
s657542570 | p02536 | u881675205 | 1601173550 | Python | PyPy3 (7.3.0) | py | Runtime Error | 357 | 117980 | 600 | def s(way):
global w
global wc
for i in way:
c[i] = 1
if wc[i] == 0:
wc[i] =1
for j in w[i]:
c[j]=1
s(w[i])
n,m = map(int,input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
w = [[] for i in range(n)]
wc = [0 for i i... |
s120181607 | p02536 | u884644739 | 1601173504 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 12260 | 765 | from functools import reduce
from collections import defaultdict
def read_int(x):
return int(x)
def dec(x):
return x - 1
def inc(x):
return x + 1
def update_dic(dic,key):
_ = dic[key]
return dic
def read_lst(x):
return list(map(read_int,x.split(' ')))
def read_roads(cnt):
return reduce(lambda x,_: x... |
s782050895 | p02536 | u306241759 | 1601173456 | Python | Python (3.8.2) | py | Runtime Error | 399 | 38632 | 730 | def dfs(now_node):
seen[now_node] = True
connect_nodes = graph[now_node]
for node in connect_nodes:
if seen[node] == True:#探索済みだったらスルー
continue
dfs(node)
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for i in range(M)]
graph = [[] for i in range(N+1)... |
s674081741 | p02536 | u912330011 | 1601173361 | Python | Python (3.8.2) | py | Runtime Error | 308 | 9708 | 608 | N, M = map(int, input().split())
rootedPoints = set()
points = []
for _ in range(M):
A, B = map(int, input().split())
rootedPoints.add(A)
rootedPoints.add(B)
Aindex = False
Bindex = False
for i, ps in enumerate(points):
if A in ps: Aindex = i
if B in ps: Bindex = i
if Aindex==False and Bindex==F... |
s474241536 | p02536 | u016843859 | 1601173176 | Python | Python (3.8.2) | py | Runtime Error | 352 | 30864 | 419 | from collections import defaultdict
N,M=map(int,input().split())
AB=list()
memo=[False]*N
G=defaultdict(list)
def dfs(i):
memo[i]=True
for j in G[i]:
if memo[j]==False:
dfs(j)
count=0
for i in range(M):
AB=list(map(int,input().split()))
G[AB[1]-1].append(AB[0]-1)
G[AB[0]-1].appen... |
s268308584 | p02536 | u400982556 | 1601173173 | Python | Python (3.8.2) | py | Runtime Error | 240 | 22916 | 331 | C = []
N, M = map(int,input().split())
for i in range(M):
a,b=input().split()
C.append(int(a))
C.append(int(b))
test = sorted(list(set(C)))
cnt = 1
x =len(test)
for i in range(1,x):
keep = test[i] - test[i-1]
if keep > 1:
keep = test[i+1] - test[i]
if keep > 1:
cnt +=1... |
s906491122 | p02536 | u797106134 | 1601173172 | Python | Python (3.8.2) | py | Runtime Error | 1255 | 693936 | 593 | import sys
sys.setrecursionlimit(10**7+1)
N,M = map(int,input().split())
ans = N
V = [i for i in range(N)]
inp = []
E =[[] for i in range(N)]
for _ in range(M):
a,b = map(int,input().split())
E[a-1].append(b-1)
E[b-1].append(a-1)
visited = [False for _ in range(N)]
def dfs(v,parent,origin):
visited[v] ... |
s876132788 | p02536 | u149966539 | 1601173172 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 31580 | 1027 | import copy
def check_root(root,num):
if(root[num-1]==num):
return num
else:
ans = check_root(root,root[num-1])
root[ans-1]=ans
return ans
def reset_root(root):
new_root = copy.copy(root)
for i in range(len(root)):
new_root[i] = check_root(root,i)
return new_root
def connect_root(root,A,... |
s944485189 | p02536 | u945342410 | 1601173076 | Python | Python (3.8.2) | py | Runtime Error | 30 | 9252 | 790 | n,m = map(int, input().split())
loadList = []
loadList.append(load)
for i in range(m):
loadList.append(list(map(int,input().split())))
cityGroupList = []
cityGroup = []
cityGroup.append(loadList[0][0])
cityGroup.append(loadList[0][1])
cityGroupList.append(cityGroup)
for oneLoad in loadList:
isAdded = False
for ... |
s144562093 | p02536 | u265506056 | 1601173055 | Python | PyPy3 (7.3.0) | py | Runtime Error | 128 | 68604 | 1358 | N,K=map(int,input().split())
A=[]
for i in range(N):
a=int(input())
A.append(a)
def segfunc(x, y):
return max(x,y)
ide_ele =0
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (... |
s021896531 | p02536 | u797106134 | 1601173042 | Python | PyPy3 (7.3.0) | py | Runtime Error | 311 | 108156 | 550 | N,M = map(int,input().split())
ans = N
V = [i for i in range(N)]
inp = []
E =[[] for i in range(N)]
for _ in range(M):
a,b = map(int,input().split())
E[a-1].append(b-1)
E[b-1].append(a-1)
visited = [False for _ in range(N)]
def dfs(v,parent,origin):
visited[v] = True
for e in E[v]:
if e == p... |
s362324134 | p02536 | u023762741 | 1601173041 | Python | Python (3.8.2) | py | Runtime Error | 2252 | 2934128 | 341 | import numpy as np
from scipy.sparse.csgraph import connected_components
N, M = map(int, input().split())
cities = np.zeros((N, N))
for i in range(M):
i1, i2 = map(int, input().split())
cities[i1-1][i2-1] = 1
cities[i2-1][i1-1] = 1
# print(cities)
# print(cities)
n, lasbel = connected_componen... |
s753977172 | p02536 | u907515644 | 1601172995 | Python | Python (3.8.2) | py | Runtime Error | 1161 | 221584 | 249 | import numpy as np
N, M= map(int, input().split())
listA=np.zeros((N,N))
for _ in range(M):
a, b=map(int, input().split())
listA[a-1][b-1]+=1
#print(listA)
a = np.sum(listA, axis=0)
#print(a)
sum=-1
for i in a:
if i == 0:
sum+=1
print(sum) |
s530026898 | p02536 | u881675205 | 1601172961 | Python | PyPy3 (7.3.0) | py | Runtime Error | 354 | 88848 | 561 | def s(way):
global w
w2 =[]
for i in way:
c[i] = 1
for j in w[i]:
if c[j] == 0:
w2.append(i)
if not w2 ==[]:
s(w2)
n,m = map(int,input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
w = [[] for i in range(n)]
c = [0 fo... |
s778190750 | p02536 | u149966539 | 1601172939 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 31404 | 996 | import copy
def check_root(root,num):
if(root[num-1]==num):
return num
else:
return check_root(root,root[num-1])
def reset_root(root):
new_root = copy.copy(root)
for i in range(len(root)):
new_root[i] = check_root(root,i)
return new_root
def connect_root(root,A,B):
if root.count(A) < root.c... |
s032452730 | p02536 | u171460096 | 1601172929 | Python | Python (3.8.2) | py | Runtime Error | 567 | 62796 | 859 | NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]
xy = [map(int, input().split()) for _ in range(M)]
x, y = [list(i) for i in zip(*xy)]
def my_index(l, x):
if x in l:
return l.index(x)
else:
return -1
group = []
for i in range(M):
index = -1
bo = True
for j in range(len(gro... |
s736798304 | p02536 | u455809703 | 1601172919 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2207 | 82748 | 343 | def inclusive_index(lst, purpose):
for i, e in enumerate(lst):
if purpose in e: return i
N, M = map(int,input().split())
lst = [str(i+1) for i in range(N)]
for _ in range(M):
A, B = input().split()
a = inclusive_index(lst, A)
b = inclusive_index(lst, B)
lst[a] = lst[a] + lst[b]
del ls... |
s621083656 | p02536 | u881675205 | 1601172820 | Python | PyPy3 (7.3.0) | py | Runtime Error | 363 | 88844 | 561 | def s(way):
global w
w2 =[]
for i in way:
c[i] = 1
for j in w[i]:
if c[j] == 0:
w2.append(i)
if not w2 ==[]:
s(w2)
n,m = map(int,input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
w = [[] for i in range(n)]
c = [0 fo... |
s305898336 | p02536 | u480139706 | 1601172819 | Python | PyPy3 (7.3.0) | py | Runtime Error | 167 | 68632 | 869 | import sys
sys.setrecursionlimit(100000)
import numpy as np
def main():
n_num, m_num = map(int, input().split())
road = np.zeros((n_num, n_num), dtype='int32')
for _ in range(m_num):
a, b = map(int, input().split())
if a > b:
a, b = b, a
road[a-1][b-1] = 1
city_... |
s144233741 | p02536 | u401810884 | 1601172816 | Python | Python (3.8.2) | py | Runtime Error | 181 | 12816 | 1169 | import math
n, M= map(int,input().split())
#AB=[]
#N = int(input())
#C = input()
parents = [-1] * n
def find( x):
if parents[x] < 0:
return x
else:
parents[x] = find(parents[x])
return parents[x]
def union(x, y):
x = find(x)
y = find(y)
if x == y:
return
if p... |
s055620053 | p02536 | u300114786 | 1601172732 | Python | Python (3.8.2) | py | Runtime Error | 317 | 28060 | 1499 | 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 = ... |
s360319866 | p02536 | u480139706 | 1601172703 | Python | Python (3.8.2) | py | Runtime Error | 2216 | 189600 | 869 | import sys
sys.setrecursionlimit(100000)
import numpy as np
def main():
n_num, m_num = map(int, input().split())
road = np.zeros((n_num, n_num), dtype='int32')
for _ in range(m_num):
a, b = map(int, input().split())
if a > b:
a, b = b, a
road[a-1][b-1] = 1
city_... |
s923984446 | p02536 | u959139907 | 1601172688 | Python | PyPy3 (7.3.0) | py | Runtime Error | 327 | 90592 | 2232 | # 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... |
s492581341 | p02536 | u517682687 | 1601172679 | Python | PyPy3 (7.3.0) | py | Runtime Error | 297 | 79980 | 1439 | class DSU:
def __init__(self, n):
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a, b):
assert 0 <= a < self._n
assert 0 <= b < self._n
x, y = self.leader(a), self.leader(b)
if x == y: return x
if -self.parent_or_size[x] < -self.parent_or_size... |
s184500425 | p02536 | u944396627 | 1601172656 | Python | Python (3.8.2) | py | Runtime Error | 372 | 24152 | 772 | class UnionFind:
pairs = {}
def __init__(self, n):
for i in range(n):
self.pairs[i] = i
def set(self, s, t):
if s in self.pairs and self.pairs[s] != s:
self.pairs[t] = s
else:
self.pairs[s] = t
def root(self, x):
if self.pairs[x] == x... |
s143050792 | p02536 | u352198227 | 1601172652 | Python | Python (3.8.2) | py | Runtime Error | 251 | 24996 | 727 | a = list(map(int,input().split()))
N = a[0]
M = a[1]
cities = [0] * N
roads = []
lands = {}
for i in range(M):
a = list(map(int,input().split()))
roads.append([a[0], a[1]])
for r in roads:
if cities[r[0]-1] == 0:
cities[r[0]-1] = r[0]
lands[r[0]-1] = [r[0]]
if cities[r[1]-1] == ... |
s759715802 | p02536 | u881675205 | 1601172638 | Python | PyPy3 (7.3.0) | py | Runtime Error | 336 | 88256 | 555 | def s(way):
global w
w2 =[]
for i in way:
for j in w[i]:
if c[j] == 0:
w2.append(i)
c[i] = 1
if not w2 ==[]:
s(w2)
n,m = map(int,input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
w = [[] for i in range(n)]
c = [0 for i in... |
s091612125 | p02536 | u865383026 | 1601172630 | Python | Python (3.8.2) | py | Runtime Error | 2207 | 70816 | 630 | from sys import setrecursionlimit
def Search(n):
L[n-1] = 1
for i in R[n]:
if L[i-1] == 0:
Search(i)
setrecursionlimit(200000)
N, M = map(int, input().split())
L = [1] * N
R = {}
ans = -1
for i in range(M):
A, B = map(int, input().split())
if A not in R:
R[A] = set()
if B not in R:
R[B] = ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.