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
s884808634
p02536
u600195339
1601170335
Python
Python (3.8.2)
py
Runtime Error
273
31968
554
from collections import deque from collections import defaultdict n, m = map(int, input().split()) g = defaultdict(list) s = set(list(range(1, n+1))) ans = 0 for i in range(m): a, b = map(int, input().split()) g[a].append(b) while s: root = s.pop() q = deque() q.append(root) done = set() ...
s350481945
p02536
u582803594
1601170335
Python
Python (3.8.2)
py
Runtime Error
144
9664
150
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 num = L.count(1) print(N-num)
s836277941
p02536
u327498205
1601170330
Python
Python (3.8.2)
py
Runtime Error
286
28080
2180
class AlgUnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n #各要素の親要素の番号を格納するリスト 要素が根(ルート)の場合は-(そのグループの要素数)を格納する def find(self, x): #要素xが属するグループの根を返す if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) ...
s304475739
p02536
u993808866
1601170300
Python
PyPy3 (7.3.0)
py
Runtime Error
131
68608
522
N, M = map(int, input().split()) Pajew = [i for i in range(n)] import sys sys.setrecursionlimit(1000000) def find(x, Pajew): if Pajew[x] == x: return x else: a = find(Pajew[x], Pajew) Pajew[x] =a return a def unite(x, y): x = find(x, Pajew) y = find(y, Pajew) if x !...
s442892527
p02536
u516483179
1601170276
Python
PyPy3 (7.3.0)
py
Runtime Error
310
77304
1355
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 =...
s205773395
p02536
u600195339
1601170275
Python
Python (3.8.2)
py
Runtime Error
253
31812
556
from collections import deque from collections import defaultdict n, m = map(int, input().split()) g = defaultdict(list) s = set(list(range(1, n+1))) ans = 0 for i in range(m): a, b = map(int, input().split()) g[a].append(b) while s: root = s.pop() q = deque() q.append(root) done = set() ...
s813831872
p02536
u575354126
1601170260
Python
Python (3.8.2)
py
Runtime Error
185
27780
1220
import sys import math,bisect sys.setrecursionlimit(10 ** 5) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict def I(): return int(sys.stdin.readline()) def neo(): return map(int, sys.stdin.readline().split()) def Neo(): return list(map...
s022671959
p02536
u514441044
1601170256
Python
Python (3.8.2)
py
Runtime Error
298
31868
1239
from collections import Counter import string import math import sys def array_int(): return [int(i) for i in sys.stdin.readline().split()] def vary(number_of_variables): if number_of_variables==1: return int(sys.stdin.readline()) if number_of_variables>=2: return map(int,sys.stdin.readline(...
s715837926
p02536
u600195339
1601170240
Python
PyPy3 (7.3.0)
py
Runtime Error
265
87272
556
from collections import deque from collections import defaultdict n, m = map(int, input().split()) g = defaultdict(list) s = set(list(range(1, n+1))) ans = 0 for i in range(m): a, b = map(int, input().split()) g[a].append(b) while s: root = s.pop() q = deque() q.append(root) done = set() ...
s718312783
p02536
u433375322
1601170231
Python
Python (3.8.2)
py
Runtime Error
189
12776
1177
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 = ...
s257258101
p02536
u038408819
1601170167
Python
PyPy3 (7.3.0)
py
Runtime Error
321
90836
1340
n, m = map(int, input().split()) ab = [list(map(int, input().split())) for i in range(m)] 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(se...
s849571003
p02536
u658600714
1601170154
Python
PyPy3 (7.3.0)
py
Runtime Error
200
72300
177
import math n,m=map(int,input().split()) r=[0]*n for i in range (m): a,b=map(int,input().split()) r[a]+=1 r[b]+=1 ma = max(r) if ma>=n-1: print(0) else: print(n-1-ma)
s645442354
p02536
u712284046
1601170137
Python
Python (3.8.2)
py
Runtime Error
323
22256
316
N, M = map(int, input().split()) City_list = [[i] for i in range(N)] ans = N - 1 - M for i in range(M): Ai, Bi = map(int, input().split()) if City_list[Ai] == City_list[Bi]: ans += 1 else: City_list[Ai] = City_list[Ai] + City_list[Bi] City_list[Bi] = City_list[Ai] print(ans)
s531322647
p02536
u650939551
1601170129
Python
Python (3.8.2)
py
Runtime Error
382
27368
1656
# Python3 program to print DFS traversal # from a given given graph from collections import defaultdict viz = [0]*1005 # This class represents a directed graph using # adjacency list representation class Graph: # Constructor def __init__(self): # default dictionary to store graph self.graph...
s260479701
p02536
u772705651
1601170122
Python
Python (3.8.2)
py
Runtime Error
478
13052
438
N, M = map(int, input().split()) connect = {} no_connection = [n + 1 for n in range(N)] for _ in range(M): a, b = map(int, input().split()) no_connection.remove(a) no_connection.remove(b) for group_idx, group_set in connect.items(): if a in group_set: connect[group_idx] |= set([a, b]) br...
s524658712
p02536
u940652437
1601170109
Python
Python (3.8.2)
py
Runtime Error
29
9164
129
n,m=map(int,input().split()) t=[] for i in range(m): a=int(input()) t.append(a) l = len(set(t)) ans = n-l print(ans)
s790924363
p02536
u994147425
1601170088
Python
Python (3.8.2)
py
Runtime Error
209
12948
1369
# https://note.nkmk.me/python-union-find/ 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...
s052843743
p02536
u694665829
1601170082
Python
PyPy3 (7.3.0)
py
Runtime Error
2256
1902664
263
n, m = map(int,input().split()) M = [[0 for _ in range(n)] for i in range(n)] for i in range(m): a, b = map(int,input().split()) M[a][b] = 1 cnt = 0 for i in range(n-1): if all(M[i][j] == 0 for j in range(1+i, n)): cnt += 1 print(cnt)
s971137964
p02536
u941645670
1601170074
Python
Python (3.8.2)
py
Runtime Error
29
9008
254
from atcoder import dsu n,m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] ds = dsu.DSU(n) for i in ab: ds.merge(i[0]-1,i[1]-1) s = ds.groups() ans = 0 for i in s: if len(i)==1: ans+=1 print(ans)
s202980593
p02536
u551310735
1601170074
Python
Python (3.8.2)
py
Runtime Error
2206
28312
975
# H4CKOM N = int(100100) g = [[] for i in range(N)] vis = [False for i in range(N)] vis2 = [False for i in range(N)] def add_edge(u, v): g[u].append(v) def dfs1(v): vis2[v] = True for to in g[v]: if not vis2[to]: dfs1(to) def dfs2(v): global ans vis[v] = True ans += 1 ...
s447834942
p02536
u501364195
1601170071
Python
Python (3.8.2)
py
Runtime Error
152
12156
570
N, M = map(int, input().split()) group = [] tf = [] for i in range(M): A, B = map(int, input().split()) if A and B not in tf: tf.append(A) tf.append(B) group.append([A,B]) else: if A not in tf: tf.append(A) for j in range(len(group)): if B in group[j]: group[i].append...
s361273390
p02536
u844872527
1601170066
Python
Python (3.8.2)
py
Runtime Error
226
27236
660
def MII(): return map(int, input().split()) def LII(): return list(map(int, input().split())) #bit = [i>>j&1 for j in range(n)] n,m=MII() connect_city=[LII() for _ in range(m)] groups=[[1]] for i in range(m): a,b=connect_city[i] flag=0 for j,group in enumerate(groups): if a in group: ...
s168802201
p02536
u766486294
1601170060
Python
Python (3.8.2)
py
Runtime Error
239
26228
2061
import types _atcoder_code = """ # Python port of AtCoder Library. __version__ = '0.0.1' """ atcoder = types.ModuleType('atcoder') exec(_atcoder_code, atcoder.__dict__) _atcoder_dsu_code = """ import typing class DSU: ''' Implement (union by size) + (path compression) Reference: Zvi Galil and Gius...
s174247129
p02536
u954153335
1601170031
Python
Python (3.8.2)
py
Runtime Error
35
12852
278
n,m=map(int,input().split()) data=list(range(n)) cnt=n-1 def find(x): if data[x]==x: return x else: find(data[x]) for i in range(m): a,b=map(int,input().split()) a=find(a-1) b=find(b-1) if a!=b: data[a]=b cnt-=1 print(cnt)
s206081474
p02536
u501278784
1601169956
Python
Python (3.8.2)
py
Runtime Error
30
9412
463
import collections sys.setrecursionlimit(10**6) def dfs(visited,v,adj): visited[v]=True for i in adj[v]: if not visited[i]: dfs(visited,i,adj) adj=collections.defaultdict(list) n,m=map(int,input().split()) visited=[False]*n for i in range(m): u,v=map(int,input().split()) adj[u...
s113400375
p02536
u536017058
1601169905
Python
PyPy3 (7.3.0)
py
Runtime Error
220
75464
922
class UnionFind: __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: while self._roots[x] >= 0: x = self._roots[x] return x def ...
s116380386
p02536
u941645670
1601169903
Python
Python (3.8.2)
py
Runtime Error
220
27268
233
#c n,m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] ds = dsu.DSU(n) for i in ab: ds.merge(i[0]-1,i[1]-1) s = ds.groups() ans = 0 for i in s: if len(i)==1: ans+=1 print(ans)
s463628389
p02536
u519339498
1601169879
Python
Python (3.8.2)
py
Runtime Error
167
26232
2085
import types _atcoder_code = """ # Python port of AtCoder Library. __version__ = '0.0.1' """ atcoder = types.ModuleType('atcoder') exec(_atcoder_code, atcoder.__dict__) _atcoder_dsu_code = """ import typing class DSU: ''' Implement (union by size) + (path compression) Reference: Zvi Galil and Gius...
s350250321
p02536
u473172054
1601169865
Python
Python (3.8.2)
py
Runtime Error
2206
18408
303
n, m = map(int, input().split()) par = [i for i in range(n)] for i in range(m): a, b = map(int, input().split()) if a > b: a, b = b, a cur = par[b] par[b] = par[a] while(cur in par): idx = par.index(cur) par[idx] = par[a] ans = len(set(par)) - 1 print(ans)
s256867018
p02536
u420332509
1601169864
Python
Python (3.8.2)
py
Runtime Error
241
31152
422
from sys import setrecursionlimit setrecursionlimit(1000000) def l_in(type_): return list(map(type_, input().split())) def i_in(): return int(input()) def m_in(type_): return map(type_, input().split()) def r_in(n, type_): return [type_(input()) for _ in range(n)] n, m = m_in(int) ab = [list(m_in(int)) for _ in range(...
s776872046
p02536
u668190572
1601169862
Python
PyPy3 (7.3.0)
py
Runtime Error
152
69360
346
import sys,io,os I = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline I = input n,m = map(int, I().split()) p=[-1]*(n+1) s=[0]*(n+1) S=n-1 def t(a): while p[a] != -1: a = p[a] return a for _ in range(m): a,b=map(int, I().split()) a,b = t(a), t(b) if a != b: S -= 1 if s[a] > s[b]: a,b = b,a p[a] = b...
s820726941
p02536
u544587633
1601169849
Python
PyPy3 (7.3.0)
py
Runtime Error
154
68568
1006
#!/usr/bin/env python3 import sys import networkx as nx def solve(N: int, M: int, A: "List[int]", B: "List[int]"): G = nx.Graph() for i in range(1, N+1): G.add_node(i) for i in range(M): G.add_edge(A[i], B[i]) if nx.is_connected(G): print(0) else: print(nx.number_...
s943329973
p02536
u461513098
1601169830
Python
Python (3.8.2)
py
Runtime Error
334
26980
536
def dfs(v): global visited visited[v] = True for nv in graph[v]: if nv in graph[v]: if not visited[nv]: dfs(nv) if __name__ == "__main__": N, M = map(int, input().split()) graph = [[] for _ in range(N)] visited = [False]*N for _ in range(M): A, B...
s202783717
p02536
u724549242
1601169820
Python
Python (3.8.2)
py
Runtime Error
214
12740
628
class UnionFind(): 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]) return self.parents[x] def union(self, x, y): x = self.find(x)...
s561310003
p02536
u514401521
1601169807
Python
PyPy3 (7.3.0)
py
Runtime Error
288
80732
899
import sys sys.setrecursionlimit(10**5) class UnionFind: def __init__(self, n): self.d = [] for _ in range(n): self.d.append(-1) def find(self, x): if self.d[x] < 0: return x else: self.d[x] = self.find(self.d[x]) return self.d...
s054890300
p02536
u867826040
1601169798
Python
Python (3.8.2)
py
Runtime Error
2240
2859224
297
from scipy.sparse.csgraph import connected_components import numpy as np n,m = map(int,input().split()) g = np.zeros((n,n),dtype=np.int) for i in range(m): ai,bi = map(int,input().split()) g[ai-1][bi-1] = 1 g[bi-1][ai-1] = 1 r = connected_components(g,return_labels=False) print(r-1)
s965758137
p02536
u514390882
1601169786
Python
Python (3.8.2)
py
Runtime Error
337
26968
429
N, M = map(int, input().split()) e = [[] for _ in range(N)] for i in range(M): A, B = map(int, input().split()) A -= 1 B -= 1 e[A].append(B) e[B].append(A) # print(e) def dfs(n, k): seen[n] = k # print(seen) for i in e[n]: if seen[i] != -1: continue dfs(i, k) seen = [-1...
s179868099
p02536
u501278784
1601169782
Python
PyPy3 (7.3.0)
py
Runtime Error
712
115516
435
import collections def dfs(visited,v,adj): visited[v]=True for i in adj[v]: if not visited[i]: dfs(visited,i,adj) adj=collections.defaultdict(list) n,m=map(int,input().split()) visited=[False]*n for i in range(m): u,v=map(int,input().split()) adj[u-1].append(v-1) adj[v-...
s977844901
p02536
u433375322
1601169779
Python
Python (3.8.2)
py
Runtime Error
218
14332
2057
class UnionFind(): """ unionfindtree のクラス グループを管理するデータ構造. 全てのメソッドの計算量が O(log(n)) よりも小さい init: 管理対象の個数 n を用いて初期化 find: ある要素 x の親がどの要素か返す union: ある要素 x と y が属しているグループを結合して1つのグループとする msize: ある要素 x が属するグループの大きさを返す """ def __init__(self, n): ...
s071079976
p02536
u803865203
1601169759
Python
Python (3.8.2)
py
Runtime Error
202
12896
1303
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 = ...
s454045053
p02536
u551310735
1601169753
Python
Python (3.8.2)
py
Runtime Error
2206
28144
970
# H4CKOM N = 100100 g = [[] for i in range(N)] vis = [False for i in range(N)] vis2 = [False for i in range(N)] def add_edge(u, v): g[u].append(v) def dfs1(v): vis2[v] = True for to in g[v]: if not vis2[to]: dfs1(to) def dfs2(v): global ans vis[v] = True ans += 1 fo...
s546471764
p02536
u514401521
1601169727
Python
PyPy3 (7.3.0)
py
Runtime Error
281
80980
859
class UnionFind: def __init__(self, n): self.d = [] for _ in range(n): self.d.append(-1) def find(self, x): if self.d[x] < 0: return x else: self.d[x] = self.find(self.d[x]) return self.d[x] def union(self, x, y): ...
s033998108
p02536
u682467216
1601169725
Python
Python (3.8.2)
py
Runtime Error
158
13636
2506
# coding=utf-8 from math import floor, ceil, sqrt, factorial, log, gcd, log10 from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappop, heappush, ...
s856750350
p02536
u766486294
1601169722
Python
Python (3.8.2)
py
Runtime Error
238
26376
2020
import types _atcoder_code = """ # Python port of AtCoder Library. __version__ = '0.0.1' """ atcoder = types.ModuleType('atcoder') exec(_atcoder_code, atcoder.__dict__) _atcoder_dsu_code = """ import typing class DSU: ''' Implement (union by size) + (path compression) Reference: Zvi Galil and Gius...
s124500045
p02536
u551310735
1601169689
Python
Python (3.8.2)
py
Runtime Error
32
9800
969
# H4CKOM N = 10010 g = [[] for i in range(N)] vis = [False for i in range(N)] vis2 = [False for i in range(N)] def add_edge(u, v): g[u].append(v) def dfs1(v): vis2[v] = True for to in g[v]: if not vis2[to]: dfs1(to) def dfs2(v): global ans vis[v] = True ans += 1 for...
s676680777
p02536
u379894480
1601169655
Python
Python (3.8.2)
py
Runtime Error
29
9164
86
a,b,c,d=map(int,input().split()) if d<a or c>b: print("No") else: print("Yes")
s027429041
p02536
u581634684
1601169648
Python
Python (3.8.2)
py
Runtime Error
243
27644
845
from sys import stdin, stdout from collections import defaultdict input = stdin.readline class Graph: def __init__(self,V): self.V = V self.adj = [[] for i in range(V)] def DFSUtil(self, temp, v, visited): visited[v] = True temp.append(v) for i in self.adj[v]: if visited[i] == False: temp = ...
s378047619
p02536
u016843859
1601169642
Python
Python (3.8.2)
py
Runtime Error
2206
12048
398
N,M=map(int,input().split()) AB=list() memo=[False]*N def dps(G,i): memo[i]=True for j in range(len(G[i])): if (G[i][j]==1)&(memo[j]==False): dps(G,j) G=[[0]*N]*N count=0 for i in range(M): AB=list(map(int,input().split())) G[AB[0]-1][AB[1]-1]=1 G[AB[1]-1][AB[0]-1]=1 for i in ran...
s009001396
p02536
u318345739
1601169641
Python
PyPy3 (7.3.0)
py
Runtime Error
361
83784
987
class Tree: def __init__(self, N): self.N = N self.nodes = [ Node(i) for i in range(N) ] def get_root(self, node): if node.parent is None: return node root = self.get_root(node.parent) node.parent = root return root def merge(self, n1, n2): ...
s781713040
p02536
u551310735
1601169636
Python
PyPy3 (7.3.0)
py
Runtime Error
117
68920
969
# H4CKOM N = 10010 g = [[] for i in range(N)] vis = [False for i in range(N)] vis2 = [False for i in range(N)] def add_edge(u, v): g[u].append(v) def dfs1(v): vis2[v] = True for to in g[v]: if not vis2[to]: dfs1(to) def dfs2(v): global ans vis[v] = True ans += 1 for...
s321458198
p02536
u235376569
1601169611
Python
Python (3.8.2)
py
Runtime Error
202
12896
1283
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 = ...
s157744639
p02536
u514390882
1601169597
Python
PyPy3 (7.3.0)
py
Runtime Error
387
107612
440
N, M = map(int, input().split()) e = [[] for _ in range(N)] for i in range(M): A, B = map(int, input().split()) A -= 1 B -= 1 e[A].append(B) e[B].append(A) # print(e) def dfs(n, k): seen[n] = k # print(seen) for i in e[n]: if seen[i] != -1: continue dfs(i, k) return ...
s814870885
p02536
u922769680
1601169595
Python
Python (3.8.2)
py
Runtime Error
31
9012
198
N,M=map(int,input().split()) A=[list(map(int,input().split())) for i in range(M) import itertools import collections B=list(itertools.chain.from_iterable(A)) C=len(collections.Counter(B)) print(N-C)
s017619760
p02536
u688839540
1601169584
Python
Python (3.8.2)
py
Runtime Error
69
20840
368
n,m = list(map(int,input().split())) res = [[x] for x in range(1,n+1)] for _ in range(m): i,j = list(map(int,input().split())) y,z = None,None for x in res: if i in x or j in x: if y == None: y = x if j in x: break else: z = x res.remove(y) res.rem...
s860036411
p02536
u581634684
1601169575
Python
PyPy3 (7.3.0)
py
Runtime Error
223
105712
845
from sys import stdin, stdout from collections import defaultdict input = stdin.readline class Graph: def __init__(self,V): self.V = V self.adj = [[] for i in range(V)] def DFSUtil(self, temp, v, visited): visited[v] = True temp.append(v) for i in self.adj[v]: if visited[i] == False: temp = ...
s652507170
p02536
u435593586
1601169574
Python
Python (3.8.2)
py
Runtime Error
27
8976
133
n.m = map(int, input().split()) roads = [] for _ in range(m): a,b = map(int, input().split()) roads.append((a,b)) print(n-m-1)
s269423577
p02536
u581634684
1601169553
Python
PyPy3 (7.3.0)
py
Runtime Error
206
105648
876
from sys import stdin, stdout from collections import defaultdict input = stdin.readline class Graph: def __init__(self,V): self.V = V self.adj = [[] for i in range(V)] def DFSUtil(self, temp, v, visited): visited[v] = True temp.append(v) for i in self.adj[v]: if visited[i] == False: temp = ...
s611656005
p02536
u650939551
1601169529
Python
PyPy3 (7.3.0)
py
Runtime Error
168
73872
1682
# Python3 program to count non-reachable # nodes from a given source using DFS. # Graph class represents a directed graph # using adjacency list representation class Graph: def __init__(self, V): self.V = V self.adj = [[] for i in range(V)] def addEdge(self, v, w): self.adj[v].append...
s873687325
p02536
u111822487
1601169527
Python
PyPy3 (7.3.0)
py
Runtime Error
172
72004
239
l = input().split() N = int(l[0]) M = int(l[1]) arr = [0]*N retval = 0 for i in range(M): l = input().split() #A[i] = l[0] #B[i] = l[1] arr[int(l[0])] = 1 arr[int(l[1])] = 1 for i in range(N): retval += arr[i] print(N-retval)
s571734509
p02536
u326552320
1601169509
Python
Python (3.8.2)
py
Runtime Error
268
27072
767
#!/usr/bin/env python # -*- coding: utf-8 -*- # # FileName: C # CreatedDate: 2020-09-26 20:52:24 +0900 # LastModified: 2020-09-26 21:18:10 +0900 # import os import sys # import numpy as np # import pandas as pd def BFS(cnt, color, path, u): color[u] = cnt for v in path[u]: if color[v] == -1: ...
s721273846
p02536
u460009487
1601169507
Python
PyPy3 (7.3.0)
py
Runtime Error
272
86584
131
n, m = map(int, input().split()) a, b = [list(map(int,input().split())) for i in range(m)] c = a + b c = set(c) print(m-len(c)+1)
s697189682
p02536
u137226361
1601169495
Python
Python (3.8.2)
py
Runtime Error
287
13964
415
n, m = map(int, input().split()) par = [i for i in range(n)] def find(x, par): if par[x] == x: return x else: return find(par[x], par) def unite(x, y): x = find(x, par) y = find(y, par) if x != y: par[x] = y for _ in range(m): a, b = map(int, input().split()) unite...
s568700576
p02536
u138083942
1601169490
Python
PyPy3 (7.3.0)
py
Runtime Error
200
72880
1474
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 = ...
s475649636
p02536
u923270446
1601169483
Python
Python (3.8.2)
py
Runtime Error
288
26936
409
n, m = map(int, input().split()) edges = [[] for i in range(n)] visit = [False for i in range(n)] def dfs(v): visit[v] = True for i in edges[v]: if not visit[i]: dfs(i) for i in range(m): a, b = map(int, input().split()) edges[a - 1].append(b - 1) edges[b - 1].append(a - 1) cnt =...
s763289355
p02536
u460009487
1601169479
Python
PyPy3 (7.3.0)
py
Runtime Error
227
86700
143
n, m = map(int, input().split()) a, b = [list(map(int,input().split())) for i in range(m)] print(a, b) c = a + b c = set(c) print(m-len(c)+1)
s062772739
p02536
u680814872
1601169478
Python
PyPy3 (7.3.0)
py
Runtime Error
1509
772736
819
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Sep 26 17:37:27 2020 @author: divyarth """ import sys import heapq import math sys.setrecursionlimit(10000) #input=sys.stdin.readline #print=sys.stdout.write from collections import deque from collections import defaultdict from collections import Co...
s205963287
p02536
u371132735
1601169474
Python
Python (3.8.2)
py
Runtime Error
246
18916
884
class path_compressed_quick_union: def __init__(self, n): self.n = n self.data = [i for i in range(n)] self.size = [1 for i in range(n)] def root(self, p): while p != self.data[p]: self.data[p] = self.data[self.data[p]] p = self.data[p] return p ...
s728969161
p02536
u682467216
1601169473
Python
PyPy3 (7.3.0)
py
Runtime Error
232
80112
2536
# coding=utf-8 from math import floor, ceil, sqrt, factorial, log, gcd, log10 from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappop, heappush, ...
s646186075
p02536
u813042907
1601169447
Python
Python (3.8.2)
py
Runtime Error
27
9180
146
n,m=map(int,input().split()) list=[] for i in range(m): list.append([]) list[i].append(int(input())) list[i].append(int(input())) print(n-m)
s133818891
p02536
u125205981
1601169439
Python
Python (3.8.2)
py
Runtime Error
368
58632
524
from scipy.sparse.csgraph import connected_components from scipy.sparse import csr_matrix from sys import stdin def makeConnected(n, connections): l = list(zip(*connections)) d = [1] * len(connections) a = csr_matrix((d, (l[0], l[1])), (n, n)) return connected_components(a, return_labels=0) def main...
s180973592
p02536
u255898796
1601169428
Python
Python (3.8.2)
py
Runtime Error
316
40052
1433
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 = ...
s534899593
p02536
u136843617
1601169428
Python
Python (3.8.2)
py
Runtime Error
238
26328
1701
import typing class DSU: ''' Implement (union by size) + (path compression) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0): self._n = n self.parent_or_size = [-1] * n def...
s752736768
p02536
u745561510
1601169415
Python
Python (3.8.2)
py
Runtime Error
2206
26992
543
N, M = map(int, input().split()) G = [[] for _ in range(N)] seen = [False] * N for _ in range(M): A, B = map(lambda x: int(x) - 1, input().split()) G[A].append(B) G[B].append(A) def dfs(x, G, seen, before): seen[x] = True for next in G[x]: if next == before: continue i...
s800072337
p02536
u990726146
1601169408
Python
Python (3.8.2)
py
Runtime Error
308
27832
1399
N, M = map(int, input().split()) ab = [0] * M for i in range(M): ab[i] = list(map(int, input().split())) import sys sys.setrecursionlimit(100500) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: ret...
s677725103
p02536
u085186789
1601169406
Python
Python (3.8.2)
py
Runtime Error
26
9160
144
N, M = map(int,input().split()) for x in range(1, M - 1): print('{0:2d} {1:3d} {2:4d}'.format(int(input()), int(input()))) print(N - (M + 1))
s737449195
p02536
u575239123
1601169399
Python
Python (3.8.2)
py
Runtime Error
214
12764
1211
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] def union(self, x, y): x = sel...
s550274664
p02536
u111822487
1601169395
Python
PyPy3 (7.3.0)
py
Runtime Error
96
68840
214
import numpy as np l = input().split() N = int(l[0]) M = int(l[1]) arr = [0]*N for i in range(M): l = input().split() #A[i] = l[0] #B[i] = l[1] arr[int(l[0])] = 1 arr[int(l[1])] = 1 print(N-np.sum(arr))
s934908972
p02536
u145915236
1601169385
Python
PyPy3 (7.3.0)
py
Runtime Error
301
79972
1346
from sys import setrecursionlimit class UnionFind: def __init__(self, n): self._n = n self.parent_or_size = [-1] * n def union(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n x, y = self.find(a), self.find(b) if x == y: return x if -self.par...
s711353638
p02536
u802781234
1601169385
Python
PyPy3 (7.3.0)
py
Runtime Error
323
95820
749
def N(): return int(input()) def L(): return list(map(int,input().split())) def NL(n): return [list(map(int,input().split())) for i in range(n)] mod = pow(10,9)+7 #import numpy as np import sys import math import collections par = [] def init(n): for i in range(n): par.append(i) def root(x): ...
s069409330
p02536
u793868662
1601169377
Python
PyPy3 (7.3.0)
py
Runtime Error
285
75424
1545
def resolve(): 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...
s048473592
p02536
u531599639
1601169358
Python
Python (3.8.2)
py
Runtime Error
2206
13264
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 = ...
s742565648
p02536
u028973125
1601169351
Python
Python (3.8.2)
py
Runtime Error
143
13004
1340
import sys 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): ...
s303641397
p02536
u414920281
1601169341
Python
PyPy3 (7.3.0)
py
Runtime Error
301
74824
1744
class UnionFind: def __init__(self,n): self.n=n self.parent=[i for i in range(n)] self.rank=[1]*n#木の高さ self.size=[1]*n#size[i]はiを根とするグループのサイズ def find(self,x):#xの根(親)を返す if self.parent[x]==x: return x else: self.parent[x]=self.find(self.pa...
s156116419
p02536
u452512115
1601169329
Python
Python (3.8.2)
py
Runtime Error
230
18876
1470
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 = ...
s986017675
p02536
u607884285
1601169317
Python
Python (3.8.2)
py
Runtime Error
198
10620
778
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 = ...
s176005574
p02536
u895408600
1601169292
Python
Python (3.8.2)
py
Runtime Error
300
28076
1298
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 = se...
s993794652
p02536
u145915236
1601169279
Python
PyPy3 (7.3.0)
py
Runtime Error
308
80000
1284
class UnionFind: def __init__(self, n): self._n = n self.parent_or_size = [-1] * n def union(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n x, y = self.find(a), self.find(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_si...
s065165517
p02536
u519339498
1601169270
Python
Python (3.8.2)
py
Runtime Error
132
12880
1883
''' Created on 2020/09/26 @author: harurun ''' #UnionFind(要素数)で初期化 class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n #parents 各要素の親番号を格納するリストを返す #要素xが属するグループを返す def find(self, x): if self.parents[x] < 0: return x else: ...
s602304799
p02536
u990726146
1601169228
Python
Python (3.8.2)
py
Runtime Error
316
27996
1356
N, M = map(int, input().split()) ab = [0] * M for i in range(M): ab[i] = list(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.paren...
s810595763
p02536
u516483179
1601169198
Python
PyPy3 (7.3.0)
py
Runtime Error
267
75304
1305
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 = ...
s293188367
p02536
u226849101
1601169192
Python
Python (3.8.2)
py
Runtime Error
2248
3530280
385
import numpy as np from scipy.sparse.csgraph import connected_components N,M = map(int, input().split()) A = [-1 for i in range(M)] B = [-1 for i in range(M)] mat = np.zeros((N,N),dtype=np.uint8) for i in range(M): A[i],B[i] = map(int, input().split()) for i in range(M): mat[A[i]-1][B[i]-1] = 1 mat[B[i]-...
s966267805
p02536
u693666240
1601169176
Python
PyPy3 (7.3.0)
py
Runtime Error
425
108680
580
mod = 10**9 + 7 def go(v): global used, g used[v] = True for i in range(len(g[v])): if used[g[v][i]] == False: go(g[v][i]) def solve(): n, m = map(int, input().split()) ans = 0 global g, used g = [[] for i in range(n + 1)] used = [False for i in range(n + 1)] for ...
s544806915
p02536
u509661905
1601169166
Python
Python (3.8.2)
py
Runtime Error
27
9096
685
#!/usr/bin/env python3 # from typing import * import atcoder.dsu # def solve(N: int, M: int, A: List[int], B: List[int]) -> int: def solve(N, M, A, B): dsu = atcoder.dsu.DSU(N) for i in range(M): dsu.merge(A[i] - 1, B[i] - 1) num_groups = len(dsu.groups()) return num_groups - 1 # generated ...
s443014671
p02536
u760771686
1601169146
Python
PyPy3 (7.3.0)
py
Runtime Error
270
75364
1301
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 = ...
s433069475
p02536
u651109406
1601169144
Python
Python (3.8.2)
py
Runtime Error
37
10580
721
class unionfind(): def __init__(self, n): self.parents = [-1 for i in range(n)] def find(self, a): if self.parents[a] < 0: return a self.parents[a] = self.find(a) return self.parents[a] def union(self, x, y): x, y = self.find(x), self.find(y) ...
s215186030
p02536
u457460736
1601169139
Python
Python (3.8.2)
py
Runtime Error
217
15936
1607
import math import collections import itertools import copy def YesNo(Bool): if(Bool): print("YES") else: print("NO") return class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: ...
s519676777
p02536
u531599639
1601169138
Python
Python (3.8.2)
py
Runtime Error
203
12784
1289
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 = ...
s097887858
p02536
u680814872
1601169132
Python
PyPy3 (7.3.0)
py
Runtime Error
1450
773396
841
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Sep 26 17:37:27 2020 @author: divyarth """ import sys import heapq import math sys.setrecursionlimit(10000) #input=sys.stdin.readline #print=sys.stdout.write from collections import deque from collections import defaultdict from collections import Co...
s419815142
p02536
u758815106
1601169130
Python
Python (3.8.2)
py
Runtime Error
337
29216
2195
import types _atcoder_code = """ # Python port of AtCoder Library. __version__ = '0.0.1' """ atcoder = types.ModuleType('atcoder') exec(_atcoder_code, atcoder.__dict__) _atcoder_dsu_code = """ import typing class DSU: ''' Implement (union by size) + (path compression) Reference: Zvi Galil and Gius...
s153209351
p02536
u289547799
1601169128
Python
PyPy3 (7.3.0)
py
Runtime Error
321
107788
470
n, m = map(int, input().split()) # n = (頂点の数), m = (辺の数) graph = [[] for _ in range(n)] for i in range(m): a, b = map(int, input().split()) graph[a-1].append(b) graph[b-1].append(a) seen = [False]*n def dfs(v): global graph global seen seen[v] = True for next_v in graph[v]: if seen[next_v-1]: ...