message stringlengths 2 49.9k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 446 108k | cluster float64 13 13 | __index_level_0__ int64 892 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
You are given a rooted tree with N vertices. The vertices are numbered 0, 1, ..., N-1. The root is Vertex 0, and the parent of Vertex i (i = 1, 2, ..., N-1) is Vertex p_i.
Initially, an integer a_i is written in Vertex i. Here, (a_0, a_1, ..., a_{N-... | instruction | 0 | 36,719 | 13 | 73,438 |
"Correct Solution:
```
from collections import deque
def get_children(ps):
children = [set() for _ in range(n)]
for i, p in enumerate(ps):
children[p].add(i + 1)
return children
def make_levels(cs):
levels_set = []
levels_dict = {}
queue = deque([(0, 0)])
while queue:
i, ... | output | 1 | 36,719 | 13 | 73,439 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a rooted tree with N vertices. The vertices are numbered 0, 1, ..., N-1. The root is Vertex 0, and the parent of Vertex i (i = 1, 2, ..., N-1) is Vertex p_i.
Initially, an integer a_i is written in Vertex i. Here, (a_0, a_1, ..., a_{N-... | instruction | 0 | 36,720 | 13 | 73,440 |
"Correct Solution:
```
from collections import deque
from heapq import heapreplace
def get_children(ps):
children = [set() for _ in range(n)]
for i, p in enumerate(ps):
children[p].add(i + 1)
return children
def make_levels(cs):
levels = []
queue = deque([(0, 0)])
while queue:
... | output | 1 | 36,720 | 13 | 73,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a rooted tree with N vertices. The vertices are numbered 0, 1, ..., N-1. The root is Vertex 0, and the parent of Vertex i (i = 1, 2, ..., N-1) is Vertex p_i.
Initially, an integer... | instruction | 0 | 36,721 | 13 | 73,442 |
No | output | 1 | 36,721 | 13 | 73,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{2}) then degree(v_{1}) = degree(v_{2}), where d... | instruction | 0 | 36,927 | 13 | 73,854 |
Tags: constructive algorithms, dfs and similar, dp, hashing, implementation, trees
Correct Solution:
```
#!/usr/bin/env python
def longest_path():
try:
d = [-1 for _ in range(n)]
d[0] = 0; q = [0]
for i in range(n):
f = q[i]
for t in g[f]:
if d[t] == -... | output | 1 | 36,927 | 13 | 73,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{2}) then degree(v_{1}) = degree(v_{2}), where d... | instruction | 0 | 36,928 | 13 | 73,856 |
Tags: constructive algorithms, dfs and similar, dp, hashing, implementation, trees
Correct Solution:
```
from sys import *
from collections import deque
#setrecursionlimit(10**8)
n = int(input())
adj = [[] for i in range(n)]
for i in range(n-1):
u, v = map(int, stdin.readline().split())
adj[u-1].append(v-1)
... | output | 1 | 36,928 | 13 | 73,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{2}) then degree(v_{1}) = degree(v_{2}), where d... | instruction | 0 | 36,929 | 13 | 73,858 |
Tags: constructive algorithms, dfs and similar, dp, hashing, implementation, trees
Correct Solution:
```
import sys
from collections import Counter
N = int(input())
Edge = [[] for _ in range(N)]
Dim = [0]*N
for _ in range(N-1):
a, b = map(int, sys.stdin.readline().split())
a -= 1
b -= 1
Edge[a].append(b... | output | 1 | 36,929 | 13 | 73,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{2}) then degree(v_{1}) = degree(v_{2}), where d... | instruction | 0 | 36,930 | 13 | 73,860 |
Tags: constructive algorithms, dfs and similar, dp, hashing, implementation, trees
Correct Solution:
```
from collections import deque, Counter
import sys
def check_node(g, node, n):
vis = [False] * n
q = deque()
vis[node] = True
q.append((node, 0))
l_p = -1
adj = -1
while len(q) > 0:
... | output | 1 | 36,930 | 13 | 73,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{2}) then degree(v_{1}) = degree(v_{2}), where d... | instruction | 0 | 36,931 | 13 | 73,862 |
Tags: constructive algorithms, dfs and similar, dp, hashing, implementation, trees
Correct Solution:
```
from collections import deque
n = int(input())
e = [[] for i in range(n+1)]
for i in range(n - 1):
u, v = map(int, input().split())
e[u].append(v)
e[v].append(u)
dep = [-1] * (n + 1)
dep[1] = 0
q = deque([1])... | output | 1 | 36,931 | 13 | 73,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{... | instruction | 0 | 36,932 | 13 | 73,864 |
No | output | 1 | 36,932 | 13 | 73,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{... | instruction | 0 | 36,933 | 13 | 73,866 |
No | output | 1 | 36,933 | 13 | 73,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{... | instruction | 0 | 36,934 | 13 | 73,868 |
No | output | 1 | 36,934 | 13 | 73,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below.
* For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{... | instruction | 0 | 36,935 | 13 | 73,870 |
No | output | 1 | 36,935 | 13 | 73,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.
Input
The first line of input contains two integers n and m (1 ≤ n... | instruction | 0 | 36,936 | 13 | 73,872 |
No | output | 1 | 36,936 | 13 | 73,873 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with bo... | instruction | 0 | 37,135 | 13 | 74,270 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
n = int(input())
r = [[] for i in range(n + 1)]
r[1] = [0]
for i in range(n - 1):
a, b = map(int, input().split())
r[a].append(b)
r[b].append(a)
t = list(map(int, input().split()))
u, v = [0] * (n + 1), [0] * (n + 1)
for i, j in enumerate(t, 1):... | output | 1 | 37,135 | 13 | 74,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with bo... | instruction | 0 | 37,136 | 13 | 74,272 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
from sys import stdin, stdout,setrecursionlimit
from collections import defaultdict,deque,Counter,OrderedDict
from heapq import heappop,heappush
import threading
n = int(stdin.readline())
graph = [set() for x in range(n)]
for x in range(n-1):
a,b = [... | output | 1 | 37,136 | 13 | 74,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with bo... | instruction | 0 | 37,137 | 13 | 74,274 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
n = int(input())
r = [[] for i in range(n + 1)]
r[1] = [0]
for i in range(n - 1):
a, b = map(int, input().split())
r[a].append(b)
r[b].append(a)
t = list(map(int, input().split()))
u, v = [0] * (n + 1), [0] * (n + 1)
for i, j in enumerate(t, 1):... | output | 1 | 37,137 | 13 | 74,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with bo... | instruction | 0 | 37,138 | 13 | 74,276 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
from collections import defaultdict
from sys import stdin,setrecursionlimit
setrecursionlimit(10**6)
import threading
def dfs(g,node,parent,cr,req):
l=[0,0]
for i in g[node]:
if i!=parent:
t=dfs(g,i,node,cr,req)
# print(t)
l[0]=max(t[0],l[0])... | output | 1 | 37,138 | 13 | 74,277 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with bo... | instruction | 0 | 37,139 | 13 | 74,278 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
import sys
def minp():
return sys.stdin.readline().strip()
n = int(minp())
e = [0]
p = [None]*(n+1)
for i in range(n):
e.append([])
for i in range(n-1):
a, b = map(int,minp().split())
e[a].append(b)
e[b].append(a)
v = list(map(int,minp().split()))
pl... | output | 1 | 37,139 | 13 | 74,279 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with bo... | instruction | 0 | 37,140 | 13 | 74,280 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buff... | output | 1 | 37,140 | 13 | 74,281 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree T is a tree with bo... | instruction | 0 | 37,141 | 13 | 74,282 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def main():
n = int(input())
path = [[] for _ in range(n)]
for _ in range(n-1):
u1,v1 = map(lambda xx:int(xx)-1,input().split())
... | output | 1 | 37,141 | 13 | 74,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its ver... | instruction | 0 | 37,142 | 13 | 74,284 |
No | output | 1 | 37,142 | 13 | 74,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its ver... | instruction | 0 | 37,143 | 13 | 74,286 |
No | output | 1 | 37,143 | 13 | 74,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its ver... | instruction | 0 | 37,144 | 13 | 74,288 |
No | output | 1 | 37,144 | 13 | 74,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its ver... | instruction | 0 | 37,145 | 13 | 74,290 |
No | output | 1 | 37,145 | 13 | 74,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval ... | instruction | 0 | 37,147 | 13 | 74,294 |
Tags: dfs and similar, graphs
Correct Solution:
```
def dfs(edge_list, start, end):
queue = [start]
visited = [False] * len(edge_list)
while len(queue) > 0:
el = queue.pop()
for i in edge_list[el]:
if not visited[i]:
if i == end:
return True
... | output | 1 | 37,147 | 13 | 74,295 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a ... | instruction | 0 | 37,155 | 13 | 74,310 |
Yes | output | 1 | 37,155 | 13 | 74,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a ... | instruction | 0 | 37,156 | 13 | 74,312 |
Yes | output | 1 | 37,156 | 13 | 74,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a ... | instruction | 0 | 37,162 | 13 | 74,324 |
No | output | 1 | 37,162 | 13 | 74,325 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans:
... | instruction | 0 | 37,419 | 13 | 74,838 |
Tags: dfs and similar, graphs
Correct Solution:
```
def put():
return map(int, input().split())
def dfs(x,flag=1):
s,vis,ans = [x],[0]*n,['+']*m
vis[x]= 1
while s:
i = s.pop()
for j,k in graph[i]:
if vis[j]==0:
if k*flag<0:
ans[abs(k)-1]='... | output | 1 | 37,419 | 13 | 74,839 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans:
... | instruction | 0 | 37,420 | 13 | 74,840 |
Tags: dfs and similar, graphs
Correct Solution:
```
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.f... | output | 1 | 37,420 | 13 | 74,841 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans:
... | instruction | 0 | 37,421 | 13 | 74,842 |
Tags: dfs and similar, graphs
Correct Solution:
```
import sys
input = sys.stdin.readline
def put():
return map(int, input().split())
def dfs(x,flag=1):
s,vis,ans = [x],[0]*n,['+']*m
vis[x]= 1
while s:
i = s.pop()
for j,k in graph[i]:
if vis[j]==0:
if k*flag<... | output | 1 | 37,421 | 13 | 74,843 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans:
... | instruction | 0 | 37,422 | 13 | 74,844 |
Tags: dfs and similar, graphs
Correct Solution:
```
import sys
input = sys.stdin.readline
def put():
return map(int, input().split())
def dfs0(x):
s = [x]
vis = [0] * n
ans = ['+'] * m
vis[x] = 1
while s:
i = s.pop()
for j, k in graph[i]:
if (vis[j] == 0):
if (k < 0):
an... | output | 1 | 37,422 | 13 | 74,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. No... | instruction | 0 | 37,423 | 13 | 74,846 |
No | output | 1 | 37,423 | 13 | 74,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. No... | instruction | 0 | 37,424 | 13 | 74,848 |
No | output | 1 | 37,424 | 13 | 74,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. No... | instruction | 0 | 37,425 | 13 | 74,850 |
No | output | 1 | 37,425 | 13 | 74,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. No... | instruction | 0 | 37,426 | 13 | 74,852 |
No | output | 1 | 37,426 | 13 | 74,853 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200... | instruction | 0 | 37,491 | 13 | 74,982 |
"Correct Solution:
```
N, Q = map(int, input().split())
class Unionfind():
def __init__(self, n):
self.n = n
self.parents = [-1] * (n+1)
def find(self, x):
if(self.parents[x] < 0):
return x
else:
self.parents[x] = self.find(self.parents[x])
... | output | 1 | 37,491 | 13 | 74,983 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200... | instruction | 0 | 37,492 | 13 | 74,984 |
"Correct Solution:
```
n,q=map(int,input().split())
import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる
root=[i for i in range(n+1)] #自分が親なら自身の番号を、そうでないなら(元)親の番号を示す
def r(x): #親は誰?
if root[x]==x:
return x
else:
root[x]=r(root[x])
return root[x]
def unite(x,y):
x=r(x)
y=r(y)
... | output | 1 | 37,492 | 13 | 74,985 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200... | instruction | 0 | 37,493 | 13 | 74,986 |
"Correct Solution:
```
N,Q = [int(i) for i in input().split()]
L = list(range(N))
for _ in range(Q):
n,u,v = [int(i) for i in input().split()]
while u != L[u]:
u = L[u]
while v != L[v]:
v = L[v]
u,v = [max(u,v),min(u,v)]
if n == 0:
L[u] = v
else:
if u == v:
print(1)
else:
pri... | output | 1 | 37,493 | 13 | 74,987 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200... | instruction | 0 | 37,494 | 13 | 74,988 |
"Correct Solution:
```
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]
... | output | 1 | 37,494 | 13 | 74,989 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200... | instruction | 0 | 37,495 | 13 | 74,990 |
"Correct Solution:
```
class UnionFind:
def __init__(self, size):
self.par = [-1] * size
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x, y = s... | output | 1 | 37,495 | 13 | 74,991 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200... | instruction | 0 | 37,496 | 13 | 74,992 |
"Correct Solution:
```
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(se... | output | 1 | 37,496 | 13 | 74,993 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200... | instruction | 0 | 37,497 | 13 | 74,994 |
"Correct Solution:
```
# by size
# 0-indexed
class UnionFind:
N=0
parent=None
size=None
def __init__(self,N):
self.N=N
self.parent=[i for i in range(self.N)]
self.size=[1]*self.N
def root(self,x):
while x!=self.parent[x]:
self.parent[x]=self.parent[self.parent[x]]
x=self.paren... | output | 1 | 37,497 | 13 | 74,995 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200... | instruction | 0 | 37,498 | 13 | 74,996 |
"Correct Solution:
```
# 参考URL https://note.nkmk.me/python-union-find/
class UnionFind():
# 各要素の親要素の番号を格納するリスト
# 要素が根(ルート)の場合は-(そのグループの要素数)を格納する
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# 要素xが属するグループの根を返す
def find(self, x):
if self.parents[x] < 0:
... | output | 1 | 37,498 | 13 | 74,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected c... | instruction | 0 | 37,499 | 13 | 74,998 |
Yes | output | 1 | 37,499 | 13 | 74,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected c... | instruction | 0 | 37,500 | 13 | 75,000 |
Yes | output | 1 | 37,500 | 13 | 75,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected c... | instruction | 0 | 37,501 | 13 | 75,002 |
Yes | output | 1 | 37,501 | 13 | 75,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected c... | instruction | 0 | 37,502 | 13 | 75,004 |
Yes | output | 1 | 37,502 | 13 | 75,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected c... | instruction | 0 | 37,503 | 13 | 75,006 |
No | output | 1 | 37,503 | 13 | 75,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected c... | instruction | 0 | 37,504 | 13 | 75,008 |
No | output | 1 | 37,504 | 13 | 75,009 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.