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.
Problems
B'You are given a tree of n nodes. The tree is rooted at node 1 , which is not considered as a leaf regardless of its degree. Each leaf of the tree has one of the two colors: red or blue. Leaf node v initially has color s_{v} . The color of each of the internal nodes (including the root) is determined as follows. Integer k is a parameter that is same for all the nodes. You need to handle the following types of queries: The first line of the input consists of two integers n and k ( 2 <= n <= 10^{5} , -n <= k <= n ) -- the number of nodes and the initial parameter k . Each of the next n - 1 lines contains two integers u and v ( 1 <= u,v <= n ), denoting that there is an edge between vertices u and v . The next line consists of n space separated integers -- the initial array s ( -1 <= s_i <= 1 ). s_{i} = 0 means that the color of node i is red. s_{i} = 1 means that the color of node i is blue. s_{i} = -1 means that the node i is not a leaf. The next line contains an integer q ( 1 <= q <= 10^5 ), the number of queries. q lines follow, each containing a query in one of the following queries: For each query of the first type, print 0 if the color of vertex v is red, and 1 otherwise. (i) The initial tree (ii) The tree after the 3rd query (iii) The tree after the 7th query '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
59569991 |
LJZ_C |
H |
Aug. 27, 2019, 12:13 p.m. |
OK |
GNU C++11 |
TESTS |
88 |
187 |
16076800 |
|
3500 |
60202584 |
nealchen |
H |
Sept. 7, 2019, 6:32 a.m. |
OK |
GNU C++11 |
TESTS |
96 |
218 |
22118400 |
|
3500 |
60201671 |
nealchen |
H |
Sept. 7, 2019, 6:06 a.m. |
OK |
GNU C++11 |
TESTS |
96 |
233 |
20172800 |
|
3500 |
59697142 |
foreverlasting |
H |
Aug. 30, 2019, 9:03 a.m. |
OK |
GNU C++11 |
TESTS |
96 |
249 |
37683200 |
|
3500 |
61949184 |
Backseat-Stargazer |
H |
Oct. 6, 2019, 2:22 a.m. |
OK |
GNU C++11 |
TESTS |
96 |
265 |
16076800 |
|
3500 |
59648941 |
Even_Bao |
H |
Aug. 29, 2019, 7:17 a.m. |
OK |
GNU C++11 |
TESTS |
96 |
280 |
45670400 |
|
3500 |
60726525 |
yijan |
H |
Sept. 17, 2019, 2:05 p.m. |
OK |
GNU C++11 |
TESTS |
96 |
311 |
71372800 |
|
3500 |
59648492 |
slonik1111 |
H |
Aug. 29, 2019, 7:05 a.m. |
OK |
GNU C++11 |
TESTS |
96 |
327 |
23756800 |
|
3500 |
59579275 |
_BARUTO |
H |
Aug. 27, 2019, 3:20 p.m. |
OK |
GNU C++11 |
TESTS |
88 |
327 |
23756800 |
|
3500 |
59507952 |
zx2003 |
H |
Aug. 26, 2019, 6:54 a.m. |
OK |
GNU C++11 |
TESTS |
88 |
327 |
23756800 |
|
3500 |
61457720 |
idxcalcal |
H |
Sept. 29, 2019, 7:07 a.m. |
OK |
GNU C++14 |
TESTS |
96 |
218 |
119091200 |
|
3500 |
61456461 |
idxcalcal |
H |
Sept. 29, 2019, 6:30 a.m. |
OK |
GNU C++14 |
TESTS |
96 |
249 |
50176000 |
|
3500 |
60044628 |
TadijaSebez |
H |
Sept. 4, 2019, 7:48 p.m. |
OK |
GNU C++14 |
TESTS |
96 |
280 |
16793600 |
|
3500 |
59628097 |
krijgertje |
H |
Aug. 28, 2019, 4:50 p.m. |
OK |
GNU C++14 |
TESTS |
88 |
280 |
17510400 |
|
3500 |
61456288 |
idxcalcal |
H |
Sept. 29, 2019, 6:26 a.m. |
OK |
GNU C++14 |
TESTS |
96 |
280 |
56524800 |
|
3500 |
59502734 |
ecnerwala |
H |
Aug. 26, 2019, 4:01 a.m. |
OK |
GNU C++14 |
TESTS |
88 |
296 |
19763200 |
|
3500 |
60044737 |
TadijaSebez |
H |
Sept. 4, 2019, 7:51 p.m. |
OK |
GNU C++14 |
TESTS |
96 |
312 |
16793600 |
|
3500 |
61113526 |
cz_xuyixuan |
H |
Sept. 23, 2019, 12:07 p.m. |
OK |
GNU C++14 |
TESTS |
96 |
343 |
51507200 |
|
3500 |
59595720 |
foreverlasting |
H |
Aug. 28, 2019, 1:28 a.m. |
OK |
GNU C++14 |
TESTS |
88 |
358 |
39424000 |
|
3500 |
59595702 |
foreverlasting |
H |
Aug. 28, 2019, 1:27 a.m. |
OK |
GNU C++14 |
TESTS |
88 |
389 |
39424000 |
|
3500 |
63968089 |
slzxchy |
H |
Nov. 1, 2019, 8:01 a.m. |
OK |
GNU C++17 |
TESTS |
96 |
311 |
25600000 |
|
3500 |
59544019 |
Benq |
H |
Aug. 26, 2019, 8:25 p.m. |
OK |
GNU C++17 |
TESTS |
88 |
327 |
23449600 |
|
3500 |
62454658 |
gongsuidashen |
H |
Oct. 13, 2019, 5:55 a.m. |
OK |
GNU C++17 |
TESTS |
96 |
358 |
71577600 |
|
3500 |
60586207 |
Xellos |
H |
Sept. 14, 2019, 9:25 p.m. |
OK |
GNU C++17 |
TESTS |
96 |
967 |
22118400 |
|
3500 |
60153499 |
NiroBC |
H |
Sept. 6, 2019, 5:26 a.m. |
OK |
GNU C++17 |
TESTS |
96 |
1231 |
91955200 |
|
3500 |
59776541 |
cjtoribio |
H |
Aug. 30, 2019, 11:45 p.m. |
OK |
GNU C++17 |
TESTS |
96 |
1980 |
143052800 |
|
3500 |
61305166 |
Rabbittank |
H |
Sept. 26, 2019, 6:53 a.m. |
OK |
GNU C++17 |
TESTS |
96 |
2558 |
45772800 |
|
3500 |
59660074 |
AhemJi |
H |
Aug. 29, 2019, 12:07 p.m. |
OK |
GNU C++17 |
TESTS |
96 |
2604 |
45772800 |
|
3500 |
59978381 |
gholami1383 |
H |
Sept. 4, 2019, 7:06 a.m. |
OK |
GNU C++17 |
TESTS |
96 |
2964 |
230297600 |
|
3500 |
59978548 |
7202amin |
H |
Sept. 4, 2019, 7:10 a.m. |
OK |
GNU C++17 |
TESTS |
96 |
3025 |
230297600 |
|
3500 |
remove filters
Back to search problems