Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.
ContestId |
Name |
Phase |
Frozen |
Duration (Seconds) |
Relative Time |
Start Time |
|---|---|---|---|---|---|---|
| 1627 | Codeforces Round 766 (Div. 2) | FINISHED | False | 7200 | 134148323 | Jan. 15, 2022, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 16207 ) | C | Not Assigning | PROGRAMMING | constructive algorithms dfs and similar number theory trees |
You are given a tree of n vertices numbered from 1 to n , with edges numbered from 1 to n-1 . A tree is a connected undirected graph without cycles. You have to assign integer weights to each edge of the tree, such that the resultant graph is a prime tree. A prime tree is a tree where the weight of every path consisting of one or two edges is prime. A path should not visit any vertex twice. The weight of a path is the sum of edge weights on that path. Consider the graph below. It is a prime tree as the weight of every path of two or less edges is prime. For example, the following path of two edges: 2 to 1 to 3 has a weight of 11 + 2 = 13 , which is prime. Similarly, the path of one edge: 4 to 3 has a weight of 5 , which is also prime. Print any valid assignment of weights such that the resultant tree is a prime tree. If there is no such assignment, then print -1 . It can be proven that if a valid assignment exists, one exists with weights between 1 and 10^5 as well. The input consists of multiple test cases. The first line contains an integer t ( 1 <= q t <= q 10^4 ) -- the number of test cases. The description of the test cases follows. The first line of each test case contains one integer n ( 2 <= q n <= q 10^5 ) -- the number of vertices in the tree. Then, n-1 lines follow. The i -th line contains two integers u and v ( 1 <= q u, v <= q n ) denoting that edge number i is between vertices u and v . It is guaranteed that the edges form a tree. It is guaranteed that the sum of n over all test cases does not exceed 10^5 . For each test case, if a valid assignment exists, then print a single line containing n-1 integers a_1, a_2, ... , a_{n-1} ( 1 <= q a_i <= 10^5 ), where a_i denotes the weight assigned to the edge numbered i . Otherwise, print -1 . If there are multiple soluti |
| Codeforces Round #766 (Div. 2) Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 142876133 | ruban | C | Jan. 15, 2022, 4:26 p.m. | OK | Delphi | TESTS | 30 | 93 | 208998400 | ||
| 142874133 | Pluto_Xz | C | Jan. 15, 2022, 4:21 p.m. | OK | GNU C++14 | TESTS | 30 | 62 | 2457600 | ||
| 142909877 | 342zhuyongqi | C | Jan. 16, 2022, 3:38 a.m. | OK | GNU C++14 | TESTS | 30 | 62 | 9625600 | ||
| 142879573 | L2c | C | Jan. 15, 2022, 4:34 p.m. | OK | GNU C++14 | TESTS | 30 | 77 | 7577600 | ||
| 142909954 | 342zhuyongqi | C | Jan. 16, 2022, 3:39 a.m. | OK | GNU C++14 | TESTS | 30 | 77 | 9625600 | ||
| 142909820 | bfsdw1qaz | C | Jan. 16, 2022, 3:37 a.m. | OK | GNU C++14 | TESTS | 30 | 77 | 11980800 | ||
| 142910827 | Vanthoci | C | Jan. 16, 2022, 4 a.m. | OK | GNU C++14 | TESTS | 30 | 78 | 1638400 | ||
| 142904238 | HalfStar | C | Jan. 16, 2022, 12:22 a.m. | OK | GNU C++14 | TESTS | 30 | 78 | 6144000 | ||
| 142908067 | wcarry afmafk chen_qian | C | Jan. 16, 2022, 2:50 a.m. | OK | GNU C++14 | TESTS | 30 | 78 | 7577600 | ||
| 142904979 | zouguangchen | C | Jan. 16, 2022, 1 a.m. | OK | GNU C++14 | TESTS | 30 | 78 | 7987200 | ||
| 142905707 | CCSU_Wine | C | Jan. 16, 2022, 1:31 a.m. | OK | GNU C++14 | TESTS | 30 | 78 | 9625600 | ||
| 142876284 | saratcsss | C | Jan. 15, 2022, 4:26 p.m. | OK | .NET Core C# | TESTS | 30 | 312 | 27136000 |
Back to search problems