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 tags and a correct Python 3 solution for this coding contest problem.
You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: in all paths that start at v and end at some ot... | instruction | 0 | 41,484 | 13 | 82,968 |
Tags: data structures, dfs and similar, dp, trees
Correct Solution:
```
import io, os;from collections import Counter, defaultdict, deque
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
_default = default;self._func = func;self._len = len(data);self._size = _size = 1 << (self._len - 1)... | output | 1 | 41,484 | 13 | 82,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: in all paths that start at v and end at some ot... | instruction | 0 | 41,485 | 13 | 82,970 |
Tags: data structures, dfs and similar, dp, trees
Correct Solution:
```
import io
import os
from collections import Counter, defaultdict, deque
# https://raw.githubusercontent.com/cheran-senthil/PyRival/master/pyrival/data_structures/LazySegmentTree.py
class LazySegmentTree:
def __init__(self, data, default=0, f... | output | 1 | 41,485 | 13 | 82,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: in all paths that start at v and end at some ot... | instruction | 0 | 41,486 | 13 | 82,972 |
Tags: data structures, dfs and similar, dp, trees
Correct Solution:
```
import io, os;from collections import Counter, defaultdict, deque
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
_default = default;self._func = func;self._len = len(data);self._size = _size = 1 << (self._len - 1)... | output | 1 | 41,486 | 13 | 82,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: in all paths that start at v and end at some ot... | instruction | 0 | 41,487 | 13 | 82,974 |
Tags: data structures, dfs and similar, dp, trees
Correct Solution:
```
import io, os
from collections import Counter, defaultdict, deque
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
_default = default
self._func = func
self._len = len(data)
self._size = _s... | output | 1 | 41,487 | 13 | 82,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: in all paths that start at v and end at some ot... | instruction | 0 | 41,488 | 13 | 82,976 |
Tags: data structures, dfs and similar, dp, trees
Correct Solution:
```
import io, os
from collections import Counter, defaultdict, deque
class LazySegmentTree:
def __init__(self, data, default=0, func=max):
_default = default
self._func = func
self._len = len(data)
self._size = _s... | output | 1 | 41,488 | 13 | 82,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: ... | instruction | 0 | 41,489 | 13 | 82,978 |
No | output | 1 | 41,489 | 13 | 82,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: ... | instruction | 0 | 41,490 | 13 | 82,980 |
No | output | 1 | 41,490 | 13 | 82,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a tree with n vertices. Each vertex i has a value a_i associated with it.
Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: ... | instruction | 0 | 41,491 | 13 | 82,982 |
No | output | 1 | 41,491 | 13 | 82,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that t... | instruction | 0 | 41,637 | 13 | 83,274 |
No | output | 1 | 41,637 | 13 | 83,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that t... | instruction | 0 | 41,638 | 13 | 83,276 |
No | output | 1 | 41,638 | 13 | 83,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that t... | instruction | 0 | 41,639 | 13 | 83,278 |
No | output | 1 | 41,639 | 13 | 83,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that t... | instruction | 0 | 41,640 | 13 | 83,280 |
No | output | 1 | 41,640 | 13 | 83,281 |
Provide a correct Python 3 solution for this coding contest problem.
We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects Vertex a_i and Vertex b_i.
Consider adding zero or more edges in G, and let H be the graph resulted.
Find the number of graphs H that satisfy the following conditions, mo... | instruction | 0 | 41,853 | 13 | 83,706 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
mod=998244353
N=int(input())
E=[[] for i in range(N+1)]
for i in range(N-1):
x,y=map(int,input().split())
E[x].append(y)
E[y].append(x)
Q=[1]
D=[-1]*(N+1)
D[1]=0
while Q:
x=Q.pop()
for to in E[x]:
if D[to]==-1:
D[to]... | output | 1 | 41,853 | 13 | 83,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects Vertex a_i and Vertex b_i.
Consider adding zero or more edges in G, and let H be the graph resulted.
Find the numb... | instruction | 0 | 41,854 | 13 | 83,708 |
No | output | 1 | 41,854 | 13 | 83,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects Vertex a_i and Vertex b_i.
Consider adding zero or more edges in G, and let H be the graph resulted.
Find the numb... | instruction | 0 | 41,855 | 13 | 83,710 |
No | output | 1 | 41,855 | 13 | 83,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects Vertex a_i and Vertex b_i.
Consider adding zero or more edges in G, and let H be the graph resulted.
Find the numb... | instruction | 0 | 41,856 | 13 | 83,712 |
No | output | 1 | 41,856 | 13 | 83,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects Vertex a_i and Vertex b_i.
Consider adding zero or more edges in G, and let H be the graph resulted.
Find the numb... | instruction | 0 | 41,857 | 13 | 83,714 |
No | output | 1 | 41,857 | 13 | 83,715 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex 1, in which every leaf (excluding root) is... | instruction | 0 | 42,107 | 13 | 84,214 |
Tags: dfs and similar, graphs, implementation, trees
Correct Solution:
```
AND = "AND"
OR = "OR"
XOR = "XOR"
NOT = "NOT"
IN = "IN"
OPS = {
AND: AND,
OR: OR,
XOR: XOR,
NOT: NOT,
}
class Node:
def __init__(self, num):
self.num = num
self.op = None
self.parent = None
... | output | 1 | 42,107 | 13 | 84,215 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex 1, in which every leaf (excluding root) is... | instruction | 0 | 42,108 | 13 | 84,216 |
Tags: dfs and similar, graphs, implementation, trees
Correct Solution:
```
import sys
input=sys.stdin.readline
n=int(input())
stack=[]
children=[]
for i in range(n):
children.append([])
parent=[-1]*n
nodes=[-1]*n
inputs=[]
functions=[-1]*n
for i in range(n):
a=list(map(str,input().split()))
r=a[0]
if r=='IN':
... | output | 1 | 42,108 | 13 | 84,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bytelandian Tree Factory produces trees for all kinds of industrial applications. You have been tasked with optimizing the production of a certain type of tree for an especially large and import... | instruction | 0 | 42,185 | 13 | 84,370 |
No | output | 1 | 42,185 | 13 | 84,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bytelandian Tree Factory produces trees for all kinds of industrial applications. You have been tasked with optimizing the production of a certain type of tree for an especially large and import... | instruction | 0 | 42,186 | 13 | 84,372 |
No | output | 1 | 42,186 | 13 | 84,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bytelandian Tree Factory produces trees for all kinds of industrial applications. You have been tasked with optimizing the production of a certain type of tree for an especially large and import... | instruction | 0 | 42,187 | 13 | 84,374 |
No | output | 1 | 42,187 | 13 | 84,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bytelandian Tree Factory produces trees for all kinds of industrial applications. You have been tasked with optimizing the production of a certain type of tree for an especially large and import... | instruction | 0 | 42,188 | 13 | 84,376 |
No | output | 1 | 42,188 | 13 | 84,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a directed acyclic graph G, consisting of n vertexes, numbered from 0 to n - 1. The graph contains n edges numbered from 0 to n - 1. An edge with number i connects vertexes i and (i + 1... | instruction | 0 | 42,419 | 13 | 84,838 |
No | output | 1 | 42,419 | 13 | 84,839 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a directed acyclic graph G, consisting of n vertexes, numbered from 0 to n - 1. The graph contains n edges numbered from 0 to n - 1. An edge with number i connects vertexes i and (i + 1... | instruction | 0 | 42,420 | 13 | 84,840 |
No | output | 1 | 42,420 | 13 | 84,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a directed acyclic graph G, consisting of n vertexes, numbered from 0 to n - 1. The graph contains n edges numbered from 0 to n - 1. An edge with number i connects vertexes i and (i + 1... | instruction | 0 | 42,421 | 13 | 84,842 |
No | output | 1 | 42,421 | 13 | 84,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a directed acyclic graph G, consisting of n vertexes, numbered from 0 to n - 1. The graph contains n edges numbered from 0 to n - 1. An edge with number i connects vertexes i and (i + 1... | instruction | 0 | 42,422 | 13 | 84,844 |
No | output | 1 | 42,422 | 13 | 84,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav... | instruction | 0 | 42,527 | 13 | 85,054 |
Yes | output | 1 | 42,527 | 13 | 85,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav... | instruction | 0 | 42,531 | 13 | 85,062 |
No | output | 1 | 42,531 | 13 | 85,063 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav... | instruction | 0 | 42,532 | 13 | 85,064 |
No | output | 1 | 42,532 | 13 | 85,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob have a tree (undirected acyclic connected graph). There are ai chocolates waiting to be picked up in the i-th vertex of the tree. First, they choose two different vertices as their... | instruction | 0 | 42,535 | 13 | 85,070 |
No | output | 1 | 42,535 | 13 | 85,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob have a tree (undirected acyclic connected graph). There are ai chocolates waiting to be picked up in the i-th vertex of the tree. First, they choose two different vertices as their... | instruction | 0 | 42,536 | 13 | 85,072 |
No | output | 1 | 42,536 | 13 | 85,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob have a tree (undirected acyclic connected graph). There are ai chocolates waiting to be picked up in the i-th vertex of the tree. First, they choose two different vertices as their... | instruction | 0 | 42,537 | 13 | 85,074 |
No | output | 1 | 42,537 | 13 | 85,075 |
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 weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed m... | instruction | 0 | 42,574 | 13 | 85,148 |
No | output | 1 | 42,574 | 13 | 85,149 |
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 weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed m... | instruction | 0 | 42,575 | 13 | 85,150 |
No | output | 1 | 42,575 | 13 | 85,151 |
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 weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed m... | instruction | 0 | 42,576 | 13 | 85,152 |
No | output | 1 | 42,576 | 13 | 85,153 |
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 weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed m... | instruction | 0 | 42,577 | 13 | 85,154 |
No | output | 1 | 42,577 | 13 | 85,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and... | instruction | 0 | 42,928 | 13 | 85,856 |
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
from collections import deque
n, k = list(map(int, input().split()))
G = [set() for _ in range(n + 1)]
q, nq = deque(), deque()
for _ in range(n - 1):
u, v = list(map(int, input().split()))
G[u].add(v)
G[v].add(u)
for u in range(1, n +... | output | 1 | 42,928 | 13 | 85,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and... | instruction | 0 | 42,929 | 13 | 85,858 |
Tags: dfs and similar, graphs, shortest paths
Correct Solution:
```
from collections import deque
n,k = map(int,input().split())
d = {}
for i in range(n):
d[i+1] = set()
for i in range(n-1):
u,v = map(int,input().split())
d[u].add(v)
d[v].add(u)
dist = {}
prev = {}
dist[1] = 0
q = deque()
q.append(1)
wh... | output | 1 | 42,929 | 13 | 85,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree ... | instruction | 0 | 42,930 | 13 | 85,860 |
No | output | 1 | 42,930 | 13 | 85,861 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree ... | instruction | 0 | 42,931 | 13 | 85,862 |
No | output | 1 | 42,931 | 13 | 85,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.
You a... | instruction | 0 | 43,103 | 13 | 86,206 |
No | output | 1 | 43,103 | 13 | 86,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.
You a... | instruction | 0 | 43,104 | 13 | 86,208 |
No | output | 1 | 43,104 | 13 | 86,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.
You a... | instruction | 0 | 43,105 | 13 | 86,210 |
No | output | 1 | 43,105 | 13 | 86,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.
You a... | instruction | 0 | 43,106 | 13 | 86,212 |
No | output | 1 | 43,106 | 13 | 86,213 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a connected undirected graph with n vertices and an integer k, you have to either:
* either find an independent set that has exactly ⌈k/2⌉ vertices.
* or find a simple cycle of length at most k.
An independent set is a set of ... | instruction | 0 | 43,124 | 13 | 86,248 |
Tags: constructive algorithms, dfs and similar, graphs, greedy, implementation, trees
Correct Solution:
```
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)############... | output | 1 | 43,124 | 13 | 86,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a connected undirected graph with n vertices and an integer k, you have to either:
* either find an independent set that has exactly ⌈k/2⌉ vertices.
* or find a simple cycle of length at most k.
An independent set is a set of ... | instruction | 0 | 43,125 | 13 | 86,250 |
Tags: constructive algorithms, dfs and similar, graphs, greedy, implementation, trees
Correct Solution:
```
import sys
from math import ceil
input = sys.stdin.readline
n, m, req = map(int, input().split())
e = [tuple(map(int, input().split())) for _ in range(m)]
g = [[] for _ in range(n + 1)]
for u, v in e:
g[... | output | 1 | 43,125 | 13 | 86,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a connected undirected graph with n vertices and an integer k, you have to either:
* either find an independent set that has exactly ⌈k/2⌉ vertices.
* or find a simple cycle of length at most k.
An independent set is a set of ... | instruction | 0 | 43,126 | 13 | 86,252 |
Tags: constructive algorithms, dfs and similar, graphs, greedy, implementation, trees
Correct Solution:
```
import math
import sys
input = sys.stdin.readline
from collections import *
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip(... | output | 1 | 43,126 | 13 | 86,253 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a connected undirected graph with n vertices and an integer k, you have to either:
* either find an independent set that has exactly ⌈k/2⌉ vertices.
* or find a simple cycle of length at most k.
An independent set is a set of ... | instruction | 0 | 43,127 | 13 | 86,254 |
Tags: constructive algorithms, dfs and similar, graphs, greedy, implementation, trees
Correct Solution:
```
import sys
input = sys.stdin.readline
from math import sqrt
n,m=map(int,input().split())
k=int(-(-sqrt(n)//1))
E=[[] for i in range(n+1)]
D=[0]*(n+1)
for i in range(m):
x,y=map(int,input().split())
E[x]... | output | 1 | 43,127 | 13 | 86,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Given a connected undirected graph with n vertices and an integer k, you have to either:
* either find an independent set that has exactly ⌈k/2⌉ vertices.
* or find a simple cycle of length at most k.
An independent set is a set of ... | instruction | 0 | 43,128 | 13 | 86,256 |
Tags: constructive algorithms, dfs and similar, graphs, greedy, implementation, trees
Correct Solution:
```
#!/usr/bin/env python3
import sys
from math import *
from collections import defaultdict
from queue import deque # Queues
from heapq import heappush, heappop # Priority Queues
# parse
lines = [... | output | 1 | 43,128 | 13 | 86,257 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.