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. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let...
instruction
0
68,716
13
137,432
"Correct Solution: ``` import sys sys.setrecursionlimit(200200) mod = 10 ** 9 + 7 N, *AB = map(int, open(0).read().split()) E = [[] for _ in range(N + 1)] for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)): E[a - 1].append((b - 1, i)) E[b - 1].append((a - 1, i)) X = [0] * N def dfs(u, i): res = 1 for...
output
1
68,716
13
137,433
Provide a correct Python 3 solution for this coding contest problem. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let...
instruction
0
68,717
13
137,434
"Correct Solution: ``` import sys sys.setrecursionlimit(500000) input = sys.stdin.readline N = int(input()); MOD=pow(10,9)+7 beki = [-1]*(N+1); beki[0] = 1; beki[1] = 2 #階乗 for i in range(2,N+1): beki[i] = beki[i-1]*2%MOD #print(beki) G = [[] for _ in range(N)] for i in range(N-1): a,b = map(int,input().split()) ...
output
1
68,717
13
137,435
Provide a correct Python 3 solution for this coding contest problem. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let...
instruction
0
68,718
13
137,436
"Correct Solution: ``` import sys sys.setrecursionlimit(505050) input = sys.stdin.buffer.readline N = int(input()) AB = [list(map(int, input().split())) for _ in range(N-1)] mod = 10**9+7 half = mod // 2 + 1 G = [[] for _ in range(N+1)] for a, b in AB: G[a].append(b) G[b].append(a) P = [0] * (N+1) Size = [0] * ...
output
1
68,718
13
137,437
Provide a correct Python 3 solution for this coding contest problem. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let...
instruction
0
68,719
13
137,438
"Correct Solution: ``` from collections import defaultdict import sys sys.setrecursionlimit(10 ** 6) def ext_euc(a, b): if b == 0: return 1, 0, a y, x, v = ext_euc(b, a % b) y -= (a // b) * x return x, y, v def mod_inv(a, mod): x, _, _ = ext_euc(a, mod) return x % mod def main():...
output
1
68,719
13
137,439
Provide a correct Python 3 solution for this coding contest problem. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let...
instruction
0
68,720
13
137,440
"Correct Solution: ``` from sys import stdin, setrecursionlimit from collections import deque setrecursionlimit(10 ** 9) INF = 1 << 60 def input(): return stdin.readline().strip() MOD = 1000000007 N = int(stdin.buffer.readline()) m = map(int, stdin.buffer.read().split()) AB = zip(m, m) G = [[] for _ in range(N...
output
1
68,720
13
137,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, whic...
instruction
0
68,721
13
137,442
Yes
output
1
68,721
13
137,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, whic...
instruction
0
68,722
13
137,444
Yes
output
1
68,722
13
137,445
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, whic...
instruction
0
68,723
13
137,446
Yes
output
1
68,723
13
137,447
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, whic...
instruction
0
68,724
13
137,448
Yes
output
1
68,724
13
137,449
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, whic...
instruction
0
68,725
13
137,450
No
output
1
68,725
13
137,451
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, whic...
instruction
0
68,726
13
137,452
No
output
1
68,726
13
137,453
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, whic...
instruction
0
68,727
13
137,454
No
output
1
68,727
13
137,455
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, whic...
instruction
0
68,728
13
137,456
No
output
1
68,728
13
137,457
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encount...
instruction
0
68,975
13
137,950
Tags: dp, dsu, trees Correct Solution: ``` """ NTC here """ #!/usr/bin/env python import os import sys from io import BytesIO, IOBase def iin(): return int(input()) def lin(): return list(map(int, input().split())) # range = xrange # input = raw_input # NCR # p = 6461335109 # N = 10**5+10 # factorialInv = [None...
output
1
68,975
13
137,951
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encount...
instruction
0
68,976
13
137,952
Tags: dp, dsu, trees Correct Solution: ``` from sys import stdin, stdout import re from random import randrange from pprint import PrettyPrinter pprint = PrettyPrinter(width=55).pprint def is_lucky(num): return re.fullmatch("[47]+", num) is not None gr = None def topo_order(u): res = [(u, None, None)] i =...
output
1
68,976
13
137,953
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encount...
instruction
0
68,977
13
137,954
Tags: dp, dsu, 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.buffer = BytesIO() ...
output
1
68,977
13
137,955
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky...
instruction
0
68,978
13
137,956
No
output
1
68,978
13
137,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky...
instruction
0
68,979
13
137,958
No
output
1
68,979
13
137,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky...
instruction
0
68,980
13
137,960
No
output
1
68,980
13
137,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky...
instruction
0
68,981
13
137,962
No
output
1
68,981
13
137,963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders t...
instruction
0
69,589
13
139,178
No
output
1
69,589
13
139,179
Provide tags and a correct Python 3 solution for this coding contest problem. Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1. Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces ro...
instruction
0
70,092
13
140,184
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writ...
output
1
70,092
13
140,185
Provide tags and a correct Python 3 solution for this coding contest problem. Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1. Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces ro...
instruction
0
70,093
13
140,186
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` import sys input = sys.stdin.buffer.readline class bit: def __init__(self, n): self.n = n self.a = [0]*(n+1) def add(self, idx, val): idx += 1 while idx < self.n: self.a[idx] += val ...
output
1
70,093
13
140,187
Provide tags and a correct Python 3 solution for this coding contest problem. Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1. Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces ro...
instruction
0
70,094
13
140,188
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` #!/usr/bin/env python import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() ...
output
1
70,094
13
140,189
Provide tags and a correct Python 3 solution for this coding contest problem. Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1. Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces ro...
instruction
0
70,095
13
140,190
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` from __future__ import print_function import sys import traceback from bisect import bisect_left, bisect_right, insort from itertools import chain, repeat, starmap from math import log from operator import add, eq, ne, gt, ge, lt, le, iadd f...
output
1
70,095
13
140,191
Provide tags and a correct Python 3 solution for this coding contest problem. Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the t...
instruction
0
70,191
13
140,382
Tags: dfs and similar, dp, trees Correct Solution: ``` n = int(input()) edges = [int(x) for x in input().split()] color = [int(x) for x in input().split()] graph = [[] for _ in range(n)] for a,b in enumerate(edges): graph[a+1].append(b) graph[b].append(a+1) dp = [[0]*2 for _ in range(n)] visited = [0]*n stack...
output
1
70,191
13
140,383
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's t...
instruction
0
70,192
13
140,384
No
output
1
70,192
13
140,385
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's t...
instruction
0
70,193
13
140,386
No
output
1
70,193
13
140,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's t...
instruction
0
70,194
13
140,388
No
output
1
70,194
13
140,389
Provide a correct Python 3 solution for this coding contest problem. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order. Cons...
instruction
0
70,491
13
140,982
"Correct Solution: ``` class CSR: def __init__(self, n: int, edges: list): self.start = [0] * (n+1) self.elist = [0] * len(edges) for e in edges: self.start[e[0]+1] += 1 for i in range(1, n+1): self.start[i] += self.start[i-1] counter...
output
1
70,491
13
140,983
Provide a correct Python 3 solution for this coding contest problem. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order. Cons...
instruction
0
70,492
13
140,984
"Correct Solution: ``` import sys sys.setrecursionlimit(10**7) def MI(): return map(int,sys.stdin.readline().rstrip().split()) class SCC: def __init__(self,N): self.N = N self.graph = [[] for _ in range(N)] self.graph_rev = [[] for _ in range(N)] self.flag = [False]*N def add_...
output
1
70,492
13
140,985
Provide a correct Python 3 solution for this coding contest problem. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order. Cons...
instruction
0
70,493
13
140,986
"Correct Solution: ``` #-------最強ライブラリSCC(Python) ver25252------ import sys sys.setrecursionlimit(1000000) class scc_graph: # n 頂点数 def __init__(s, n): s._n = n s.g = {} def num_vertices(s): return s._n # 辺を追加 frm 矢元 to 矢先 # O(1) def add_edge(s, frm, to): if frm in s.g: s.g[frm].append(to) ...
output
1
70,493
13
140,987
Provide a correct Python 3 solution for this coding contest problem. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order. Cons...
instruction
0
70,494
13
140,988
"Correct Solution: ``` import sys input = sys.stdin.readline n,m = map(int, input().split()) es = [[] for _ in range(n)] for i in range(m): a,b=map(int, input().split()) es[a].append(b) # strongly connected component def scc(es): # DFSを2回行う n_node = len(es) esinv = [[] for _ in range(n_node)] for i...
output
1
70,494
13
140,989
Provide a correct Python 3 solution for this coding contest problem. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order. Cons...
instruction
0
70,495
13
140,990
"Correct Solution: ``` from collections import deque class csr: def __init__(self,N,edges): self.start = [0]*(N+1) self.elist = [0]*len(edges) for e in edges: self.start[e[0]+1] += 1 for i in range(1,N+1): self.start[i] += self.start[i-1] counter = se...
output
1
70,495
13
140,991
Provide a correct Python 3 solution for this coding contest problem. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order. Cons...
instruction
0
70,496
13
140,992
"Correct Solution: ``` # verify-helper: PROBLEM https://judge.yosupo.jp/problem/scc import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(6 * 10 ** 5) class StronglyConnectedComponets: def __init__(self, n: int) -> None: self.n = n self.edges = [[] for _ in range(n)] self.rev...
output
1
70,496
13
140,993
Provide a correct Python 3 solution for this coding contest problem. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order. Cons...
instruction
0
70,497
13
140,994
"Correct Solution: ``` from collections import deque class csr: def __init__(self,N,edges): self.start = [0]*(N+1) self.elist = [0]*len(edges) for e in edges: self.start[e[0]+1] += 1 for i in range(1,N+1): self.start[i] += self.start[i-1] counter = se...
output
1
70,497
13
140,995
Provide a correct Python 3 solution for this coding contest problem. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order. Cons...
instruction
0
70,498
13
140,996
"Correct Solution: ``` class csr(): def __init__(self, n: int, edges: list): self.start = [0] * (n+1) self.elist = [0] * len(edges) for e in edges: self.start[e[0]+1] += 1 for i in range(1, n+1): self.start[i] += self.start[i-1] counter = self.start[::...
output
1
70,498
13
140,997
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected com...
instruction
0
70,499
13
140,998
Yes
output
1
70,499
13
140,999
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected com...
instruction
0
70,500
13
141,000
Yes
output
1
70,500
13
141,001
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected com...
instruction
0
70,501
13
141,002
Yes
output
1
70,501
13
141,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected com...
instruction
0
70,502
13
141,004
Yes
output
1
70,502
13
141,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected com...
instruction
0
70,503
13
141,006
No
output
1
70,503
13
141,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected com...
instruction
0
70,504
13
141,008
No
output
1
70,504
13
141,009
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected com...
instruction
0
70,505
13
141,010
No
output
1
70,505
13
141,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected com...
instruction
0
70,506
13
141,012
No
output
1
70,506
13
141,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake". Misha has already come ...
instruction
0
70,793
13
141,586
No
output
1
70,793
13
141,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake". Misha has already come ...
instruction
0
70,794
13
141,588
No
output
1
70,794
13
141,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake". Misha has already come ...
instruction
0
70,795
13
141,590
No
output
1
70,795
13
141,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake". Misha has already come ...
instruction
0
70,796
13
141,592
No
output
1
70,796
13
141,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice recently found some cactuses growing near her house! After several months, more and more cactuses appeared and soon they blocked the road. So Alice wants to clear them. [A cactus](https:/...
instruction
0
70,849
13
141,698
No
output
1
70,849
13
141,699