Codeforces Round 392 (Div. 2)

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
758 Codeforces Round 392 (Div. 2) FINISHED False 7200 291567323 Jan. 19, 2017, 3:05 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 552 ) E Broken Tree PROGRAMMING dfs and similar dp graphs greedy trees 2900

You are given a tree that has n vertices, which are numbered from 1 to n , where the vertex number one is the root. Each edge has weight w i and strength p i . Botanist Innokentiy, who is the only member of the jury of the Olympiad in Informatics, doesn't like broken trees. The tree is broken if there is such an edge the strength of which is less than the sum of weight of subtree's edges to which it leads. It is allowed to reduce weight of any edge by arbitrary integer value, but then the strength of its edge is reduced by the same value. It means if the weight of the edge is 10 , and the strength is 12 , then by the reducing the weight by 7 its weight will equal 3 , and the strength will equal 5 . It is not allowed to increase the weight of the edge. Your task is to get the tree, which is not broken, by reducing the weight of edges of the given tree, and also all edged should have the positive weight, moreover, the total weight of all edges should be as large as possible. It is obvious that the strength of edges can not be negative, however it can equal zero if the weight of the subtree equals zero. The first line contains the integer n ( 1 ≤ n ≤ 2·10 5 ) — the number of vertices in the tree. The next n - 1 lines contains the description of edges. Each line contains four integers x , y , w , p ( 1 ≤ x , y ≤ n , 1 ≤ w ≤ 10 9 , 0 ≤ p ≤ 10 9 ), where x and y — vertices which connect the edge (the vertex number x is the parent of the vertex number y ), w and p are the weight and the strength of the edge, accordingly. It is guaranteed that the edges describe the tree with the root in the vertex 1 . If it is impossible to get unbroken tree from the given tree, print -1 in the only line. Otherwise, the output data should contain n lines: In the first line print the number n — the number of vertices on the tree. In the next n - 1 lines print the description of edges of the resulting tree. Each line should contain four integers x , y , w , p ( 1 ≤ x , y ≤ n , 1 ≤

Tutorials

Codeforces Round #392 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
25811267 hsuppr E March 26, 2017, 5:30 a.m. OK GNU C++ TESTS 90 311 29286400 2900
25891095 Septher E March 29, 2017, 8:41 a.m. OK GNU C++ TESTS 90 327 24473600 2900
24061938 jasonvictoryan E Jan. 23, 2017, 3:22 a.m. OK GNU C++ TESTS 90 343 27648000 2900
27661475 kczno1 E June 8, 2017, 2:14 a.m. OK GNU C++ TESTS 90 374 32870400 2900
24465470 Trasier E Feb. 6, 2017, 9:06 a.m. OK GNU C++ TESTS 90 374 41369600 2900
34106661 yasugongshang E Jan. 12, 2018, 12:55 p.m. OK GNU C++ TESTS 90 390 53760000 2900
24599938 Mhammad1 E Feb. 12, 2017, 2:29 a.m. OK GNU C++ TESTS 90 405 39731200 2900
24611332 ITer E Feb. 12, 2017, 3:05 p.m. OK GNU C++ TESTS 90 420 31744000 2900
24445473 phan_trinh E Feb. 5, 2017, 5:50 a.m. OK GNU C++ TESTS 90 420 31744000 2900
28718213 vjudge5 E July 20, 2017, 8:32 a.m. OK GNU C++ TESTS 90 420 113459200 2900
45355330 Dust1404 E Nov. 6, 2018, 8:02 a.m. OK GNU C++11 TESTS 90 202 25088000 2900
63649763 vjudge1 E Oct. 28, 2019, 11:02 a.m. OK GNU C++11 TESTS 90 295 33484800 2900
26826811 blutrex E May 4, 2017, 1:49 a.m. OK GNU C++11 TESTS 90 311 20377600 2900
59216907 AllWeKnow E Aug. 21, 2019, 10:41 a.m. OK GNU C++11 TESTS 90 311 34406400 2900
38420377 Kananix E May 19, 2018, 6:55 a.m. OK GNU C++11 TESTS 90 311 46387200 2900
45348337 Created_equal E Nov. 6, 2018, 5:39 a.m. OK GNU C++11 TESTS 90 312 47411200 2900
43389839 emoairx E Sept. 24, 2018, 11:48 p.m. OK GNU C++11 TESTS 90 327 26419200 2900
38419571 Kananix E May 19, 2018, 6:30 a.m. OK GNU C++11 TESTS 90 327 80896000 2900
38420434 Dreamless_Dreams E May 19, 2018, 6:57 a.m. OK GNU C++11 TESTS 90 327 100966400 2900
38420418 Kananix E May 19, 2018, 6:57 a.m. OK GNU C++11 TESTS 90 327 100966400 2900
54434736 vjudge2 E May 21, 2019, 4:19 a.m. OK GNU C++14 TESTS 90 358 36044800 2900
26185332 luosuocumt_16 E April 7, 2017, 6:41 a.m. OK GNU C++14 TESTS 90 389 32256000 2900
25418560 songman E March 11, 2017, 8:52 p.m. OK GNU C++14 TESTS 90 405 26214400 2900
25418690 songman E March 11, 2017, 8:59 p.m. OK GNU C++14 TESTS 90 405 26214400 2900
25093187 joyfun E Feb. 28, 2017, 5:27 a.m. OK GNU C++14 TESTS 90 405 30924800 2900
29115791 52416 E Aug. 2, 2017, 3:19 a.m. OK GNU C++14 TESTS 90 405 42700800 2900
24285591 cjhahaha E Jan. 31, 2017, 9:09 a.m. OK GNU C++14 TESTS 90 420 28364800 2900
24621836 sjtsjt E Feb. 13, 2017, 6:03 a.m. OK GNU C++14 TESTS 90 420 35532800 2900
24062846 paul-lu E Jan. 23, 2017, 5:05 a.m. OK GNU C++14 TESTS 90 421 25088000 2900
23992491 natsugiri E Jan. 20, 2017, 3:34 p.m. OK GNU C++14 TESTS 90 436 22118400 2900
52599435 Gene_Liu E April 11, 2019, 11:10 a.m. OK GNU C++17 TESTS 90 342 23244800 2900
69818272 hjk1030 E Jan. 30, 2020, 6:52 a.m. OK GNU C++17 TESTS 90 404 41779200 2900
47670998 C20193618 E Dec. 29, 2018, 5:56 a.m. OK GNU C++17 TESTS 90 420 29798400 2900
44487938 InvUsr E Oct. 18, 2018, 1:20 p.m. OK GNU C++17 TESTS 90 451 32972800 2900
39525571 karasek E June 22, 2018, 6:49 p.m. OK GNU C++17 TESTS 90 452 28262400 2900
52747688 Shayan.P E April 14, 2019, 12:30 p.m. OK GNU C++17 TESTS 90 452 37785600 2900
48566104 malfple E Jan. 19, 2019, 9:38 a.m. OK GNU C++17 TESTS 90 483 39424000 2900
48566123 vjudge2 E Jan. 19, 2019, 9:38 a.m. OK GNU C++17 TESTS 90 483 39424000 2900
48518596 vjudge3 E Jan. 18, 2019, 5:46 a.m. OK GNU C++17 TESTS 90 499 71475200 2900
47445306 vjudge1 E Dec. 24, 2018, 5:46 a.m. OK GNU C++17 TESTS 90 499 71475200 2900
24287356 WonderMouse E Jan. 31, 2017, 10:37 a.m. OK Java 8 TESTS 90 530 48230400 2900
24000531 IgorKoval E Jan. 21, 2017, 1:05 a.m. OK Java 8 TESTS 90 545 59187200 2900
23987095 vanchope E Jan. 20, 2017, 11:29 a.m. OK Java 8 TESTS 90 889 155443200 2900
23997920 IgorKoval E Jan. 20, 2017, 8:13 p.m. OK Java 8 TESTS 90 904 133632000 2900
23997844 IgorKoval E Jan. 20, 2017, 8:09 p.m. OK Java 8 TESTS 90 1013 141619200 2900
24007369 stevie1024 E Jan. 21, 2017, 9:28 a.m. OK Java 8 TESTS 90 1840 213299200 2900
24062163 donli E Jan. 23, 2017, 3:48 a.m. OK Java 8 TESTS 90 1964 108236800 2900
24266991 physmatman E Jan. 30, 2017, 12:39 p.m. OK Java 8 TESTS 90 2090 148787200 2900
24267300 physmatman E Jan. 30, 2017, 12:54 p.m. OK Java 8 TESTS 90 2339 221900800 2900
23984494 yurim E Jan. 20, 2017, 9:10 a.m. OK Java 8 TESTS 90 3587 271974400 2900
47351089 vjudge5 E Dec. 22, 2018, 2:50 a.m. OK MS C++ TESTS 90 295 31232000 2900
26330660 RCG E April 13, 2017, 4:07 a.m. OK MS C++ TESTS 90 343 37376000 2900
23986509 superwatermelon E Jan. 20, 2017, 10:56 a.m. OK MS C++ TESTS 90 545 111923200 2900
24153270 AleksanderBalobanov E Jan. 26, 2017, 4:41 p.m. OK MS C++ TESTS 90 1544 48537600 2900

remove filters

Back to search problems