id stringlengths 32 32 | problem stringlengths 28 2.84k | output stringlengths 800 95.3k | source stringclasses 5
values | license stringclasses 1
value | dataset stringclasses 1
value | split stringclasses 1
value | difficulty stringclasses 30
values | solution stringlengths 8 12.3k |
|---|---|---|---|---|---|---|---|---|
8be667fb42682957580ebc058aeceb7a | Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).
Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* 0 ≤ wi ≤ 10,000
* G has arborescence(s) with the root r
Input
|V| |E| r
s0 t0 w0
s1 t1 w1
:
s|E|-1 t|E|-1 w|E|-1
, where |V| is the ... | <think>
Okay, I need to find the minimum-cost arborescence for a given directed graph with a specified root. Hmm, arborescence is like a directed tree where all edges point away from the root, and there's exactly one path from the root to every other node. Right, so the problem is to compute the sum of the weights of t... | aizu | cc-by-4.0 | code_contests | train | UNKNOWN_DIFFICULTY | def find_min_cost_arborescence(V, E, root):
if len(V) == 1:
return 0
min_in_edges = {}
for node in V:
if node == root:
continue
min_edge = None
min_weight = float('inf')
for e in E:
if e['to'] == node and e['weight'] < min_weight:
... |
0cb6b310e716e5df4a6b6d4eb076a6e3 | Today, as usual, Jerry comes up with a new puzzle for Tom. Jerry knows very well that Tom is well aware of the concepts of fibonacci series. So he intends to present the problem with a twist. By choosing any random integer Jerry asks Tom to tell whether the given number is a fibonacci number.
Input
The first line of t... | <think>
Okay, let's see. The problem is to determine if a given number is a Fibonacci number. Hmm. So, how do I check that efficiently, especially considering the constraints where N can be up to 1e9?
First, I remember that a number is part of the Fibonacci sequence if and only if 5*N^2 +4 or 5*N^2 -4 is a perfect squ... | codechef | cc-by-4.0 | code_contests | train | UNKNOWN_DIFFICULTY | import math
def is_perfect_square(x):
s = math.isqrt(x)
return s * s == x
t = int(input())
for _ in range(t):
n = int(input())
x = 5 * n * n
if is_perfect_square(x + 4) or is_perfect_square(x - 4):
print("is fibo")
else:
print("not fibo") |
b1c1c912ac90e98b2b001e4fd8e658ef | This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequenc... | <think>
Okay, I need to solve this problem where I have to replace the question marks in a bracket sequence with '(' or ')' such that the resulting sequence is regular, and the total cost is minimized. Let's think about how to approach this.
First, a regular bracket sequence must be balanced. That means the number of ... | codeforces | cc-by-4.0 | code_contests | train | VERY_HARD | import heapq
def main():
import sys
input = sys.stdin.read().split()
ptr = 0
s = input[ptr]
ptr +=1
m = s.count('?')
q_list = []
for _ in range(m):
a = int(input[ptr])
b = int(input[ptr+1])
ptr +=2
q_list.append((a, b))
open_count = s.count('(')
... |
e21b0e5fc03c44fb2dec67e730d79e14 | There are two cameras which observe the up line and the down line respectively on the double lane (please see the following figure). These cameras are located on a line perpendicular to the lane, and we call the line 'monitoring line.' (the red line in the figure)
<image>
Monitoring systems are connected to the cam... | <think>
Okay, let's see. The problem is to find the maximum time interval where no cars passed through either of the two monitoring lines. Hmm. So the cars are passing on two different lines, up and down. The monitoring systems for each line record the times when cars pass. We need to find the longest period where neit... | aizu | cc-by-4.0 | code_contests | train | UNKNOWN_DIFFICULTY | def main():
import sys
input = sys.stdin.read().split()
ptr = 0
while True:
if ptr >= len(input):
break
n = int(input[ptr])
m = int(input[ptr+1])
ptr +=2
if n ==0 and m ==0:
break
# Read tl
tl = []
if n >0:
... |
880ac66e82396460e68d79e9ccf4bf84 | "Adilbek's house is located on a street which can be represented as the OX axis. This street is real(...TRUNCATED) | "<think>\nOkay, let's see. The problem is about Adilbek wanting to install lamps along a street to i(...TRUNCATED) | codeforces | cc-by-4.0 | code_contests | train | 11 | "def main():\n import sys\n input = sys.stdin.read().split()\n idx = 0\n n = int(input[i(...TRUNCATED) |
2854c700caeb36aead0d056e349ee840 | "Simple Factorial\nYou are asked to calculate factorials of some small positive integers.\nInput\n (...TRUNCATED) | "<think>\nOkay, I need to write a Python program that calculates the factorial of several numbers gi(...TRUNCATED) | codechef | cc-by-4.0 | code_contests | train | UNKNOWN_DIFFICULTY | "t = int(input())\nfor _ in range(t):\n n = int(input())\n fact = 1\n for i in range(1, n+1(...TRUNCATED) |
01ad6a2182b351828053ede3c800073c | "In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning (...TRUNCATED) | "<think>\nOkay, so I need to solve this programming problem. Let me read the problem statement caref(...TRUNCATED) | codeforces | cc-by-4.0 | code_contests | train | VERY_HARD | "import sys\nMOD = 10**9 + 7\n\nmax_d_phi = 10**6\nmax_fact = 2 * 10**5 + 10\n\n# Precompute smalles(...TRUNCATED) |
a72176885daf756ec29facc18b89c1f7 | "The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its (...TRUNCATED) | "<think>\nOkay, let's see. I need to solve this problem where I have to determine if a given input s(...TRUNCATED) | codeforces | cc-by-4.0 | code_contests | train | interview | s = input().strip()
h_count = s.count('H')
print("Yes" if h_count % 2 == 0 else "No") |
21c0161e37c8619015e0b515ce1311f1 | "Valera loves to participate in competitions. Especially in programming contests. Today he has parti(...TRUNCATED) | "<think>\nOkay, let's tackle this problem. Hmm. So the task is to find a distribution of points for (...TRUNCATED) | codeforces | cc-by-4.0 | code_contests | train | MEDIUM | "n, k, l, r, sall, sk = map(int, input().split())\n\n# Compute the top k scores\nx = sk // k\nremain(...TRUNCATED) |
820e1759338c48d99aeb0d14a3948729 | "Raju has a very pretty girlfriend. He chats with her all day and night through his phone. His phone(...TRUNCATED) | "<think>\nOkay, I need to solve this programming problem. Let's read the problem carefully.\n\nThe p(...TRUNCATED) | hackerearth | cc-by-4.0 | code_contests | train | UNKNOWN_DIFFICULTY | "# Precompute the character to (key, presses) mapping\nmapping = {}\n\n# Key 0\nkey0 = ['_', '0']\nf(...TRUNCATED) |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 137