exec_outcome stringclasses 1
value | code_uid stringlengths 32 32 | file_name stringclasses 111
values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18
values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1
value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27
values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5
values | prob_desc_input_from stringclasses 3
values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3
values | hidden_unit_tests stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | edb9ddfd4d6ee6448e23ed4da617335e | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | //package baobab;
import java.io.*;
import java.util.*;
public class D {
public static void main(String[] args) {
Solver solver = new Solver();
}
static class Solver {
IO io;
public Solver() {
this.io = new IO();
try {
solve();
... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | df9a81cd4e21ca3eaed55c8c926f5260 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Jenish
*/
public class Ma... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | aefc58610bdfafb8d762b08bd1e5721e | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | //package aug;
import java.io.*;
import java.util.*;
public class EdRnd47 {
InputStream is;
PrintWriter out;
String INPUT = "";
//boolean codechef=false;
boolean codechef=true;
void solve()
{
int n=ni(),m=ni(),cnt=0;
Pair[] ans=new Pair[m];
HashSet<Integer... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 3739b4d51f7cf321e96d48014f334513 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
private static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int m = s.nextInt();
List<Object... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 2ea87fa964202f195661cbf5fbf53b6d | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Bit... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | f21e68022f1427f26cdfa1fc1e9fd8fd | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Relatively_Prime_Graph {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int m = scn.nextInt();
ArrayList<pair> pr = new ArrayList<>();
for (int i = 1; i <= n&&pr.size()<m; i++) {
... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | e97bac89ba143130bf83f86742e6ae28 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.BigInteger;
import java.util.regex.*;
public class Myclass {
public static ArrayList a[]=new ArrayList[200001];
/*public static int cat[]=new int [200001];
static int upto[]=new int[200001];
static int maxi[]=new int[... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 0280ffd5fb17f858f9d9e4b6c81c3461 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.PrintWriter;
import java.util.*;
public class Q3 {
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 9121f8448dc9712b133047ff1a66eb71 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;
import java.util.LinkedList;
import java.math.*;
import java.lang.*;
import java.util.PriorityQueue;
import static java.lang.Math.*;
public class solution implements Runnable {
static class Inp... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | fe287fbdb820217ca26c7f40c78ebcff | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.*;
public class C1
{
HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
static class pair
{
int x;
int y;
public pair(int x,int y)
{
this.x=x;
this.y=y;
}
}
public static int gcd(int a,int b)
{
... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 754b580b2a7c7d128115aa2dd658b399 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
public class D {
public static void main(String [] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
Task task = new Task();
task.solve(in, out);
out.close();
... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 39cfa5889f367f48cf3c9a2175b8de7e | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | /*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.*;
public class Main{
/*********************************************Constants******************************************/
static PrintWriter... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 4cdc05d8983bf20109c070a3e22a7677 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | /*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.*;
public class Main{
/*********************************************Constants******************************************/
static PrintWriter... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 5e054de36b7b557995eb20f3a69c34ea | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
im... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 71a94e642a564033422c5b7fd4e4f1b8 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.*;
import java.io.*;
import java.text.DecimalFormat;
public class Main{
final long mod = (int)1e9+7, IINF = (long)1e19;
final int MAX = (int)2e5+1, MX = (int)1e7+1, INF = (int)1e9, root = 3;
DecimalFormat df = new DecimalFormat("0.0000000000000");
double eps = 1e-9, PI = 3.14159265358... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 47b2e018b42c3a9b37d44413825682c7 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
B... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | b61167394e2d88ae1174d1b6e96a4fb6 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.Scanner;
public class DRelativelyPrimeGraph {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt(), m = scan.nextInt();
int[][] ansArr = new int[m][2];
int ansCount = 0;
if (m < n - 1) {
System... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 88c2308184d4ac0fded4511df2ad37da | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution
{
static class InputReader
{
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStrea... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 6032e7d55222f246853c9ffaa9267413 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.*;
import java.lang.*;
import java.math.*;
import java.awt.List;
import java.io.*;
/* spar5h */
public class cf4 implements Runnable{
public static long gcd (long a, long b) {
if(b == 0)
return a;
return(gcd(b, a % b));
}
public void run() {
InputReader... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 87beaefd31979e6dd534390d35410c9c | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | /*
Avocado
Naked Washington
*/
import java.io.*;
import java.util.*;
public class E
{
public static void main(String args[]) throws Exception
{
BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(infile.readLine());
... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | f742d3f429a2a5cd857a5c97fb8d7ef8 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.*;
public class problem1009D {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
int max = console.nextInt();
int reqEdges = console.nextInt();
int[] edges = new int[2*reqEdges];
int ind = 0;
if (reqEdges<max-1) {
System.out.println("Impossible");
}
... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | b82fd3d547a2b46394a898c3339a469e | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author k... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 76ed17a99d365ae524b4b949a0b0fb90 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int m=s.nextInt();
ArrayList<pair> list=new ArrayList<>();
int count=0;
for(int i=1;i<n+1;i++)
{
for(int j=i+1;j<n+1;j... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | e51237554ca5d892abcabdfb221ace0e | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.*;
import java.util.*;
public class EDU_47_D {
static final int TEST_CASES = 2;
public static void main(String[] args) {
//test(TEST_CASES);
Scanner sc = new Scanner(new BufferedReader(new
InputStreamReader(System.in)));
solve(sc);
sc.close();
}
static void test(int T) {
for (... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | a8e8fdbb958a14ab93916b60756d94d7 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;
public class relatively_prime_graph {
public static void main(String[] args) throws Exception {
new relatively_prime_graph().run();
}
public... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | ef06581b9ce6d09d83a154237ad9cc9b | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class RelativelyPrimeGraph {
private static ArrayList<Integer[]> edges;
private static int e, v;
private static int gcd(int a, int b) {
if (b == 0) return a;
else return gcd(b, a % b);
}
private static void findEdges(in... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 7592d09c6b24ad4dd0ea12f5a5c3d03b | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class TaskD {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
List<Edg... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 16d1704b7237188a4879d6bb2ee4a68e | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes |
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.management.MemoryType;
import java.net.Inet4Address;
import java.nio.charset.IllegalCharsetNameException;
import java.time.temporal.Temporal;
import ja... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 180c7db72cd79a44af2b70b5ddc93d6f | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
static class Reader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
public int read() {if (nu... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 544a351d69dd28e108937e53b344045e | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class A {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni();
int m = ni();
ArrayList<String> ls = new ArrayList<>();
if(m<n-1){... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 4368c3237264534ca4e1c7f884b05a82 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class A {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni();
int m = ni();
ArrayList<String> ls = new ArrayList<>();
if(m<n-1){... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | f9337ba1aca87329fe6c0c002cd4ebb8 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
public class templ implements Runnable {
class pair
{
int v,val;
pair(int f,int s)
{
v=f;
val=s;
}
}
public static ArrayList<Integer> g[]=new ArrayList[1000000];
... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 634f2d43e3a7feb728bb2134795241a9 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.*;
public class Main
{
static int gcd(int a,int b){
if(a==0)
return b;
else
return gcd(b%a,a);
}
public static void main(String[] args)throws IOException
{
FastReader in=new FastRead... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | df866ad0c0fb8274ce11c4adaae15d95 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class test{
static HashSet<Integer> adj[];
static int n,m;
public static void main(String[] args)throws Exception{
n = nextInt();
m = nextInt();
if(m<n-1){
System.out.println("Impossible");
return;
}
adj = new HashSet[n+1];
for(int i=... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 6c810982cc31b77140f23b1a66d4f493 | train_000.jsonl | 1531578900 | Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$ $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. T... | 256 megabytes | import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class q4 {
private static int gcd(int a, int b){
if(b==0){
return a;
}else{
return gcd(b, a%b);
}
}
public static vo... | Java | ["5 6", "6 12"] | 2 seconds | ["Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4", "Impossible"] | NoteHere is the representation of the graph from the first example: | Java 8 | standard input | [
"greedy",
"graphs",
"constructive algorithms",
"math",
"brute force"
] | 0ab1b97a8d2e0290cda31a3918ff86a4 | The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges. | 1,700 | If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ... | standard output | |
PASSED | 191908ac989bb4399549d838c5602eda | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | //package com.company;
import java.io.*;
import java.util.*;
//@author Maurice Saldivar
public class Main
{
private static class Cost implements Comparable<Cost>
{
int cost;
int position;
public Cost(int cost, int position)
{
this.cost = cost;
this.posit... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 5af775d3812e6c4c4db743c2dc2610e0 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Bracketsolver
{
public class questionMark implements Comparable<questionMark>
{
int index;
int savings;
questionMark(int _lhs, int _rhs, int _index)
... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 7b821ba078d06c0b34fd897ab6b74f5a | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | d9767a13030edbbd8c243503ce45c8a0 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.util.*;
public class cf3d {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
char[] v = in.next().trim().toCharArray();
PriorityQueue<Change> pq = new PriorityQueue<Change>();
int cnt = 0;
long cost = 0;
for(int i=0; ... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | fd2cec3304abced38dfe115c32e56ce7 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.PriorityQueue;
public class Main{
public static class Position implements Comparable<Position>{
char character;
int difference;
boolean changeable;
int location;
P... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | f24008147f6310e97044dde66dd5aad2 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.PriorityQueue;
public class Main{
public static class Position implements Comparable<Position>{
char character;
int difference;
boolean changeable;
int location;
P... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | a46d875cb286f91ecf7a45857fc81b67 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
public class Main {
private static class Cost implements Comparable<Cost> {
int open;
int close;
int id;
... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | d8adf7b321f3233cad2cc3345a960b02 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static class holder implements Comparable<holder>{
int qmIndex;
int firstCost;
... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | dd17f3b67ba2c38ad8e0381a00c9eab6 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.*;
import java.util.*;
public class Temp2 {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char[] arr = br.readLine().toCharArray();
long cost = 0;
int open=0;
PriorityQueue<Bracket> q = new PriorityQueue<... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 84e1098a0eec9be360367f6cef1c4a9a | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
String s = in.next();
char[] st = s.toCharArray();
int count = 0;
int temp, tem;
int mark = 0;
long ans = 0;
... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | d4a48efd3bf45ce291aff1da0545d4e8 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Prob3D {
static class Decision implements Comparable<Decision>
{
int index;
int openCost;
int closedCost;
public Decision(int i, int... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 1300ca8fc96dd12a0860155e1044406e | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class CodeForces {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(
new InputStreamR... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 7ffd625833407b618e8fc1e68e12457c | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class CodeForces {
public static void main(String[] args) {
FastReader reader = new FastReader();
char[] s = reader.nextLine().toCharArray();
... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | de39e6be2e62b2f6905044332701d971 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.util.PriorityQueue;
import java.util.Scanner;
public class P3D {
static class Node {
int idx;
int cost;
Node(int idx, int cost) {
this.idx = idx;
this.cost = cost;
}
}
public static void main(String[] args) {
Scanner sc = new Sca... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 41dca848d84e15c9264fb54608d10ea6 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.*;
import java.util.*;
public class Least_Cost_Bracket_Sequence {
static class brac implements Comparable<brac>{
int num,lc,rc;
int diff=lc-rc;
char choice = ')';
brac () {
}
@Override
public int compareTo(brac b) {
return this.diff - b.diff;
}
}
public static void main(String[] a... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | be02f41e5be7c214f01b79664c862864 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | /* 合 */
import java.io.*;
import java.util.*;
import java.math.*;
public final class lcbs
{
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
static FastScanner sc=new FastScanner(br);
static PrintWriter out=new PrintWriter(System.out);
static Random rnd=new Random();
stati... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | d55802b1f7b051cf022ed391557cf9cf | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.AbstractCollection;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | c337eecd55734b1713ddbfd4e0dee399 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigDecimal;
import java.math.BigInteger;
import static java.lang.Math.*;
// Solution is at the bottom of code
public class D implements Runnable{
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | e73a7060fa2de12a35f473af136e8dad | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedReader;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static BufferedReader reader;
public static String readString(){
try {
return reader.readLine().trim();
} catch (IOException e... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | b9ac7b02d9df66a2fea7f7a219e15518 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.util.PriorityQueue;
import java.util.Scanner;
public class LeastCostBracketSequence_3D {
private static class Bracket implements Comparable<Bracket> {
int costDiff;
int index;
Bracket(int costDiff, int index) {
this.costDiff = costDiff;
this.index = index;
}
public int compareTo(Bracket ... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 662eb8a556ac3253fcae385f730f5a23 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class LeastCostBracketSequence {
public static void main(String[] ar... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 9feb588cad7d357482444984a52e9c46 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
public class Main {
public static class Paren implements Comparable<Paren> {
int cost;
int index;
public Paren(int c, int i) {
cost = c;
index = i;
}
@Overri... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | b7b77c1ff17eb0d9b8b46c85455ef7f0 | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class LeastCostBracketSequence {
static class Bracket implements Comparable<Bracket> {
int idx,... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 5ea75b164701b6b12e487ea0eb375c2a | train_000.jsonl | 1267963200 | 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 sequence ... | 64 megabytes | //package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class LeastCostBracketSequence {
public static void main(String[] args) {
FastScanner s... | Java | ["(??)\n1 2\n2 8"] | 1 second | ["4\n()()"] | null | Java 8 | standard input | [
"greedy"
] | 970cd8ce0cf7214b7f2be337990557c9 | The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow m lines, where m is the number of characters "?" in the pattern. Each line contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106), where ai is the cost of replaci... | 2,600 | Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. | standard output | |
PASSED | 2a514aa3fc77f92918dbc64e293f7183 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.*;
import java.util.*;
public class Task {
public static void main(String[] args) throws IOException {
new Task().solve();
}
PrintWriter out;
int cnt = 0;
int n;
boolean[] used;
int[] use;
LinkedList<Integer>[] gr;
ArrayList<Integer> tsort = new ArrayList<Integer>();
int[] comp;
int[] ... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 591e3a7aa23e7adfaad717f4e2867074 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class tmp {
Scanner sc = new Scanner(System.in);
final int MOD = 1000000007;
ArrayList<Integer>[] tree;
boolean[] v;
int[] a;
int n, d;
void run() {
d = sc.nextInt();
n = sc.nextInt();
a = new int[n];
tree = new ArrayList[n];
for (int i ... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 8789ceade7ac0d807b3df6f4addf6ba2 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class D_277 {
MyScanner sc = new MyScanner();
final int MOD = 1000000007;
int d, n;
int[] a, f;
ArrayList<Integer>[] g;
boolean[] v;
@SuppressWarnings("unchecked")
void run() {
d = sc.nextInt();
n = sc.nextInt();
a = ... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | b6814d169154ceb83ba922c72f5be8d0 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arra... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 1c55f44bf62f94e541f324ecbbfe80d8 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.util.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class Main{
// ArrayList<Integer> lis = new ArrayList<Integer>();
// ArrayList<String> lis = new ArrayList<String>();
// PriorityQueue<P> que... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | a240f853df716ad928f12d40f7a2759b | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class ProblemD {
BufferedReader rd;
private ProblemD() throws IOException {
rd = new BufferedReader(new InputStreamReader(System.in));
compute(... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | f1a59766c5145d6fea1d87420b8b1d00 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main implements Runnable {
// leave empty to read from stdin/stdout
private static final String TASK_NAME_FOR_IO = "";
// file names
private static final String FILE_IN = TASK_NAME_FOR_IO + ".in";
private static final... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | f4b1d5ac3d19d47790ebba271cded7f2 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import javax.jws.soap.SOAPBinding.Use;
publ... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 64b5045a8722bac1dc844171c30e6c8d | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.util.*;
import java.io.*;
public class D {
public static PrintStream out = System.out;
public static InputReader in = new InputReader(System.in);
static long MOD = 1000000007;
static int D, N;
static int[] a;
static boolean[] marked;
static List<List<Integer>> adj;
public sta... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | addd6996cb1a929adab9e8311eeb784a | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes |
import java.util.*;
import java.io.*;
public class ValidSets486D {
static int P = (int) 1e9 + 7;
static List<Integer>[] tree = null;
static int[] wt = null;
static boolean[] visited = null;
static int d = 0;
static void go() {
d = in.nextInt();
int n = in.nextInt();
wt... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 641ee72ce92412f72c4de38fa6e7c85b | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class R277qDValidSets {
static int n,d;
static ArrayList<Integer> g[];
static int a[];
static long mod = (long)(1e9 + 7);
@SuppressWarnings("uncheck... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | de61196bd5a00013a0f309bae657a705 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;
public class R277D2D {
static final int MOD = (int)1e9+7;
static int[] cursor, edges, a;
static boolean[] visited, checked;
s... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | b9fe4fa0542e5e0f66eab80bbbd03db4 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.*;
import java.util.*;
public class ValidSets
{
static ArrayList<ArrayList<Integer>> adjList = new ArrayList<ArrayList<Integer>>();
static long VAL[] = new long [2050];
static long DP[] = new long [2050];
static long ans =0, MOD = 1000000007;
static long D;
static int N;
pub... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 4531b6e2da2c761736394e3975b59083 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 26eb77267809fc0827b4b7272dcfb87f | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.util.*;
public class d {
static ArrayList<Integer>[] g, tree;
static int[] vals;
static int d;
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
d = input.nextInt(); int n = input.nextInt();
g = new ArrayList[n]; tree = new ArrayList[n];
for(int i =... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | e4db52a0a8bb61950c1a46862cab3ed2 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class D {
static class Scanner{
BufferedReader br=null;
StringTokenizer tk=null;
public Scanner(){
br=new BufferedRea... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | e22f2ac081cdf5c81b7494644595ea0b | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Vector;
public class ValidSets {
public static void main(String[] args) throws IOException {
ValidSets... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | b205269d2f26f3d9564d814c591754e2 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Vector;
public class ValidSets {
public static void main(String[] args) throws IOException {
ValidSets... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | e1e3cede899effbdac9155a2d7d6b530 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
static long mod = (long)(1e9) + 7;
int n, d, w;
int[] val = new int[2005];
int[] head = new int[2005];
int[] treefrom = new int[2005*2];
int[] treeto = new int[2005*2];
int[] treenext = new int[2005*2];
b... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | a910a3a9441d006c3f9e5623904a9690 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
public class D {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
c... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 99357ab0421c9c58646027fa1b0bc041 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | // package Div2;
import java.util.ArrayList;
import java.util.Scanner;
public class CF277 {
private static final int MAXN = 2010;
private static final long MOD = (int)1e9 + 7;
private static ArrayList<Integer>[] adj = new ArrayList[MAXN];
private static int[] a = new int[MAXN];
private static long[] f = new lon... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | b6b1fc1099b25faabe28fc9ffd6c32b1 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.String... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 4492c0b14a290bf9eeb31e022d1be880 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.util.*;
import java.lang.*;
import java.lang.Math.*;
import java.io.*;
public class cf_276_A {
public static boolean[] f = new boolean[2020];
public static long MOD = 1000000007;
public static int n,d;
public static int[] a = new int[2020];
public static int[][] b = new int[2020][2020];
public sta... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | c5812f95bfec269510e7fb2025f1b852 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collecti... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | c69426d48daddc932b4892d7b5e9a3bc | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | //package codeforces;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class D {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | a6fc80d83203641d247cb39bb267aaf3 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.BufferedInputStream;
import java.util.Scanner;
/**
* Created by liverliu on 14/11/17.
*/
public class Main {
static class Node {
int val;
}
static class Edge {
public int u, v, next;
}
static Node node[] = new Node[2005];
static Edge edge[] = new Edge[4010];
... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 2a5a62be9a4b6efa988eb61f4f868676 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main{
final boolean isFileIO = false;
BufferedReader in;
PrintWriter out;
StringTokenizer st = new StringTokenizer("");
String delim = " ";
public static void main(String[] args) throws IOException {
Main ... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | ee454d706bb15d339c0292db4cdf4e4d | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | //package round277;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class D {
InputStream is;
PrintWriter out;
String INPUT = "";
int mod = 1000000007;
void solve()
... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | d20edcb417f3f7215876f62dfa5a2b6d | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.io.*;
import java.util.*;
public class validsets {
private static Reader in;
private static PrintWriter out;
public static int D, N;
public static int[] val;
public static int[] eadj, eprev, elast;
public static int eidx;
public static int mod = 1000000007;
public static void addEdge(in... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 6153bb89656ba8ebd4aacf0c3f3a6fc0 | train_000.jsonl | 1415718000 | As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.We call a set S of tree nodes valid if following conditions are satisfied: S is non-empty. S is connected. In other words, ... | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
private static final int MAX_RESULT = 1000000007;
private static int maxDiff = 0;
private static class Node{
public int index;
public int value;
public ArrayList<Node> neighbors;
public Node(int index, int value){
this.index... | Java | ["1 4\n2 1 3 2\n1 2\n1 3\n3 4", "0 3\n1 2 3\n1 2\n2 3", "4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4"] | 1 second | ["8", "3", "41"] | NoteIn the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition. | Java 7 | standard input | [
"dp",
"dfs and similar",
"trees",
"math"
] | 88bb9b993ba8aacd6a7cf137415ef7dd | The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000). The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000). Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is gua... | 2,100 | Print the number of valid sets modulo 1000000007. | standard output | |
PASSED | 742f722d947cfeb9f99d357af4646166 | train_000.jsonl | 1560677700 | Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a pos... | 512 megabytes | import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n = sc.nextInt();
Str... | Java | ["7\n1234567", "3\n101"] | 2 seconds | ["1801", "11"] | NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the ... | Java 11 | standard input | [
"implementation",
"greedy",
"strings"
] | 08bce37778b7bfe478340d5c222ae362 | The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leadi... | 1,500 | Print a single integer — the smallest number Dima can obtain. | standard output | |
PASSED | a7296fb262f538772ae654ccd4ac06eb | train_000.jsonl | 1560677700 | Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a pos... | 512 megabytes | import java.math.BigInteger;
import java.util.Stack;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
BigInteger one = new BigInteger("0");
Scanner input = new Scanner(System.in);
int len = input.nextInt();
String s = input.next();
BigInteger x,y,an... | Java | ["7\n1234567", "3\n101"] | 2 seconds | ["1801", "11"] | NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the ... | Java 11 | standard input | [
"implementation",
"greedy",
"strings"
] | 08bce37778b7bfe478340d5c222ae362 | The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leadi... | 1,500 | Print a single integer — the smallest number Dima can obtain. | standard output | |
PASSED | 7041a69ac89afcf87fd2373f6734d77f | train_000.jsonl | 1560677700 | Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a pos... | 512 megabytes | // practice with kaiboy
import java.io.*;
import java.util.*;
public class CF1181B extends PrintWriter {
CF1181B() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1181B o = new CF1181B(); o.main(); o.flush();
}
int split(byte[] cc, int l, int n, int[] a... | Java | ["7\n1234567", "3\n101"] | 2 seconds | ["1801", "11"] | NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the ... | Java 11 | standard input | [
"implementation",
"greedy",
"strings"
] | 08bce37778b7bfe478340d5c222ae362 | The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leadi... | 1,500 | Print a single integer — the smallest number Dima can obtain. | standard output | |
PASSED | 9062d43529a947639982a7e2cb306735 | train_000.jsonl | 1560677700 | Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a pos... | 512 megabytes |
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int len;
len = input.nextInt();
String ss = input.nextLine();
ss = input.nextLine();
BigInteger a = new BigIn... | Java | ["7\n1234567", "3\n101"] | 2 seconds | ["1801", "11"] | NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the ... | Java 11 | standard input | [
"implementation",
"greedy",
"strings"
] | 08bce37778b7bfe478340d5c222ae362 | The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leadi... | 1,500 | Print a single integer — the smallest number Dima can obtain. | standard output | |
PASSED | e8c07919aa4114870523a335237cd971 | train_000.jsonl | 1560677700 | Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a pos... | 512 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputReader input = new InputReade... | Java | ["7\n1234567", "3\n101"] | 2 seconds | ["1801", "11"] | NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the ... | Java 11 | standard input | [
"implementation",
"greedy",
"strings"
] | 08bce37778b7bfe478340d5c222ae362 | The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leadi... | 1,500 | Print a single integer — the smallest number Dima can obtain. | standard output | |
PASSED | 258fcca1fd73ec4674b7c545abb886b1 | train_000.jsonl | 1560677700 | Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a pos... | 512 megabytes |
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Split_the_Number {
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st == null || !st.hasMoreEle... | Java | ["7\n1234567", "3\n101"] | 2 seconds | ["1801", "11"] | NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the ... | Java 11 | standard input | [
"implementation",
"greedy",
"strings"
] | 08bce37778b7bfe478340d5c222ae362 | The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leadi... | 1,500 | Print a single integer — the smallest number Dima can obtain. | standard output | |
PASSED | 0fac4b8221e037d77db50a75e31e87f6 | train_000.jsonl | 1560677700 | Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a pos... | 512 megabytes | import java.util.*;
import java.math.*;
import java.io.*;
public class pro{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int l = input.nextInt();
String n = input.next();
BigInteger x = null, y = null, z = null;
boolean f = false, ff = false, fa = false;
if(n.charAt(l... | Java | ["7\n1234567", "3\n101"] | 2 seconds | ["1801", "11"] | NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the ... | Java 11 | standard input | [
"implementation",
"greedy",
"strings"
] | 08bce37778b7bfe478340d5c222ae362 | The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leadi... | 1,500 | Print a single integer — the smallest number Dima can obtain. | standard output | |
PASSED | 40bc1dc260a77b9472b23052ce187d34 | train_000.jsonl | 1560677700 | Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a pos... | 512 megabytes | // package cp;
import java.io.*;
import java.math.*;
import java.util.*;
public class Cf_one {
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(System.out);
Readers.init(System.in);
int l=Readers.nextInt();
String s=Readers.next();
int ll=-1;
int rr=-1;
fo... | Java | ["7\n1234567", "3\n101"] | 2 seconds | ["1801", "11"] | NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the ... | Java 11 | standard input | [
"implementation",
"greedy",
"strings"
] | 08bce37778b7bfe478340d5c222ae362 | The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leadi... | 1,500 | Print a single integer — the smallest number Dima can obtain. | standard output | |
PASSED | 2fbf913f8d361bccadd8c8a3eb1bbe70 | train_000.jsonl | 1349623800 | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 256 megabytes | //package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
/**
* Created by uzer on 02.03.2016.
*/
public class Team {
public static void main(String[] args) throws IOException {
Scanner in = ... | Java | ["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"] | 2 seconds | ["2", "1"] | NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won'... | Java 7 | standard input | [
"greedy",
"brute force"
] | 3542adc74a41ccfd72008faf983ffab5 | The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Va... | 800 | Print a single integer — the number of problems the friends will implement on the contest. | standard output | |
PASSED | 626fc3f3394c8717ca207b80b253dab2 | train_000.jsonl | 1349623800 | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 256 megabytes | import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
public class PlayGround {
public static void main(String[] args) throws Exception {
Ed... | Java | ["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"] | 2 seconds | ["2", "1"] | NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won'... | Java 7 | standard input | [
"greedy",
"brute force"
] | 3542adc74a41ccfd72008faf983ffab5 | The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Va... | 800 | Print a single integer — the number of problems the friends will implement on the contest. | standard output | |
PASSED | 38c1458ab9fffdd6e29cd3282197da23 | train_000.jsonl | 1349623800 | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 256 megabytes | import java.util.Scanner;
public class team {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int c = 0;
int d = 0;
for(int i=0;i<n;i++) {
for(int j=0; j< 3 ; j++) {
int a = in.nextInt();
c += a;
a = 0;
}
if(c >= 2) {
d +=... | Java | ["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"] | 2 seconds | ["2", "1"] | NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won'... | Java 7 | standard input | [
"greedy",
"brute force"
] | 3542adc74a41ccfd72008faf983ffab5 | The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Va... | 800 | Print a single integer — the number of problems the friends will implement on the contest. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.