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 (an undirected connected acyclic graph) consisting of n vertices and n - 1 edges. A number is written on each edge, each number is either 0 (let's call such edges 0 -edges) or 1 (those are 1 -edges). Let's call an ordered pair of vertices (x, y) ( x ne y ) valid if, while traversing the simple path from x to y , we never go through a 0 -edge after going through a 1 -edge. Your task is to calculate the number of valid pairs in the tree. The first line contains one integer n ( 2 <= n <= 200000 ) -- the number of vertices in the tree. Then n - 1 lines follow, each denoting an edge of the tree. Each edge is represented by three integers x_i , y_i and c_i ( 1 <= x_i, y_i <= n , 0 <= c_i <= 1 , x_i ne y_i ) -- the vertices connected by this edge and the number written on it, respectively. It is guaranteed that the given edges form a tree. Print one integer -- the number of valid pairs of vertices. The picture corresponding to the first example: "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
65659204 |
asorak |
D |
Nov. 24, 2019, 11:42 a.m. |
OK |
Clang++17 Diagnostics |
TESTS |
73 |
280 |
3788800 |
|
2300 |
54176455 |
fluffyowl |
D |
May 15, 2019, 2:03 p.m. |
OK |
D |
TESTS |
73 |
358 |
36761600 |
|
2300 |
53669536 |
Denor |
D |
May 2, 2019, 12:27 p.m. |
OK |
Delphi |
TESTS |
73 |
187 |
12390400 |
|
2300 |
55170289 |
sansen |
D |
June 5, 2019, 4:49 p.m. |
OK |
GNU C11 |
TESTS |
73 |
46 |
1843200 |
|
2300 |
55129277 |
sansen |
D |
June 5, 2019, 2:24 p.m. |
OK |
GNU C11 |
TESTS |
73 |
46 |
1843200 |
|
2300 |
53704875 |
Noetu |
D |
May 3, 2019, 12:42 p.m. |
OK |
GNU C11 |
TESTS |
73 |
124 |
3174400 |
|
2300 |
53976430 |
luogu_bot2 |
D |
May 11, 2019, 4:27 a.m. |
OK |
GNU C++11 |
TESTS |
73 |
46 |
4403200 |
|
2300 |
55292743 |
Umi |
D |
June 8, 2019, 8:27 a.m. |
OK |
GNU C++11 |
TESTS |
73 |
46 |
4812800 |
|
2300 |
67968674 |
chdyFZH |
D |
Dec. 30, 2019, 2:13 p.m. |
OK |
GNU C++11 |
TESTS |
73 |
46 |
6041600 |
|
2300 |
55611027 |
ReaLNero1 |
D |
June 16, 2019, 5:44 a.m. |
OK |
GNU C++11 |
TESTS |
73 |
46 |
6144000 |
|
2300 |
53701444 |
Sooke |
D |
May 3, 2019, 10:43 a.m. |
OK |
GNU C++11 |
TESTS |
73 |
46 |
6144000 |
|
2300 |
53699970 |
b1z1da |
D |
May 3, 2019, 9:45 a.m. |
OK |
GNU C++11 |
TESTS |
73 |
46 |
6144000 |
|
2300 |
57182053 |
luogu_bot3 |
D |
July 17, 2019, 7:34 a.m. |
OK |
GNU C++11 |
TESTS |
73 |
61 |
4403200 |
|
2300 |
53741550 |
secret42 |
D |
May 4, 2019, 2:08 p.m. |
OK |
GNU C++11 |
TESTS |
73 |
61 |
4403200 |
|
2300 |
53735617 |
M_sea |
D |
May 4, 2019, 9:24 a.m. |
OK |
GNU C++11 |
TESTS |
73 |
61 |
4403200 |
|
2300 |
64102027 |
cmwqf |
D |
Nov. 2, 2019, 3:48 p.m. |
OK |
GNU C++11 |
TESTS |
73 |
61 |
5939200 |
|
2300 |
53630995 |
natsugiri |
D |
May 1, 2019, 3:36 p.m. |
OK |
GNU C++14 |
TESTS |
73 |
109 |
3174400 |
|
2300 |
55221422 |
rainboy |
D |
June 6, 2019, 7:53 p.m. |
OK |
GNU C++14 |
TESTS |
73 |
109 |
3174400 |
|
2300 |
53961397 |
rdd6584 |
D |
May 10, 2019, 2:26 p.m. |
OK |
GNU C++14 |
TESTS |
73 |
124 |
6451200 |
|
2300 |
53628593 |
_greedy |
D |
May 1, 2019, 3:26 p.m. |
OK |
GNU C++14 |
TESTS |
73 |
124 |
7168000 |
|
2300 |
53767200 |
OO0OO0OO0OO0 |
D |
May 5, 2019, 1:32 a.m. |
OK |
GNU C++14 |
TESTS |
73 |
139 |
3174400 |
|
2300 |
61342900 |
_HossamYehia_ |
D |
Sept. 27, 2019, 12:50 a.m. |
OK |
GNU C++14 |
TESTS |
73 |
139 |
8601600 |
|
2300 |
53686816 |
wangxwgk |
D |
May 3, 2019, 1:43 a.m. |
OK |
GNU C++14 |
TESTS |
73 |
139 |
18944000 |
|
2300 |
53683769 |
PK_PRANTO |
D |
May 2, 2019, 9:33 p.m. |
OK |
GNU C++14 |
TESTS |
73 |
140 |
3174400 |
|
2300 |
53984897 |
updiandong |
D |
May 11, 2019, 9:05 a.m. |
OK |
GNU C++14 |
TESTS |
73 |
140 |
3174400 |
|
2300 |
60038841 |
cs71107 |
D |
Sept. 4, 2019, 5:39 p.m. |
OK |
GNU C++14 |
TESTS |
73 |
140 |
3174400 |
|
2300 |
53626410 |
panoIe |
D |
May 1, 2019, 3:19 p.m. |
OK |
GNU C++17 |
TESTS |
73 |
61 |
15667200 |
|
2300 |
53651725 |
swust5120177231 |
D |
May 2, 2019, 1:45 a.m. |
OK |
GNU C++17 |
TESTS |
73 |
62 |
4710400 |
|
2300 |
54018131 |
supremeyu |
D |
May 12, 2019, 8:04 a.m. |
OK |
GNU C++17 |
TESTS |
73 |
109 |
7168000 |
|
2300 |
53789310 |
TeeEye |
D |
May 5, 2019, 11:57 a.m. |
OK |
GNU C++17 |
TESTS |
73 |
124 |
6348800 |
|
2300 |
60777374 |
S.K |
D |
Sept. 18, 2019, 2:55 p.m. |
OK |
GNU C++17 |
TESTS |
73 |
124 |
8601600 |
|
2300 |
53891186 |
NelsonGomesNeto |
D |
May 9, 2019, 12:16 a.m. |
OK |
GNU C++17 |
TESTS |
73 |
140 |
1638400 |
|
2300 |
53845289 |
vjudge1 |
D |
May 7, 2019, 10:29 a.m. |
OK |
GNU C++17 |
TESTS |
73 |
140 |
3174400 |
|
2300 |
53893948 |
kal0rona |
D |
May 9, 2019, 3:52 a.m. |
OK |
GNU C++17 |
TESTS |
73 |
140 |
3276800 |
|
2300 |
53688376 |
fanqeixi |
D |
May 3, 2019, 2:52 a.m. |
OK |
GNU C++17 |
TESTS |
73 |
140 |
3584000 |
|
2300 |
53708686 |
NelsonGomesNeto |
D |
May 3, 2019, 2:29 p.m. |
OK |
GNU C++17 |
TESTS |
73 |
140 |
4505600 |
|
2300 |
54021818 |
ak_j17_258749 |
D |
May 12, 2019, 10:12 a.m. |
OK |
Go |
TESTS |
73 |
155 |
9830400 |
|
2300 |
62461334 |
synapse |
D |
Oct. 13, 2019, 8:22 a.m. |
OK |
Go |
TESTS |
73 |
374 |
11366400 |
|
2300 |
60482952 |
smtcoder |
D |
Sept. 13, 2019, 11:22 a.m. |
OK |
Go |
TESTS |
73 |
436 |
74240000 |
|
2300 |
53944363 |
emma |
D |
May 10, 2019, 5:38 a.m. |
OK |
Go |
TESTS |
73 |
467 |
47923200 |
|
2300 |
53726964 |
jenish9599 |
D |
May 4, 2019, 5:04 a.m. |
OK |
Java 8 |
TESTS |
73 |
155 |
0 |
|
2300 |
53695998 |
bluesky111 |
D |
May 3, 2019, 7:46 a.m. |
OK |
Java 8 |
TESTS |
73 |
202 |
2662400 |
|
2300 |
65789600 |
Agnimandur |
D |
Nov. 26, 2019, 9:11 p.m. |
OK |
Java 8 |
TESTS |
73 |
218 |
0 |
|
2300 |
55221421 |
Dukkha |
D |
June 6, 2019, 7:53 p.m. |
OK |
Java 8 |
TESTS |
73 |
218 |
0 |
|
2300 |
54251001 |
aakashjaiswal |
D |
May 16, 2019, 5:14 p.m. |
OK |
Java 8 |
TESTS |
73 |
218 |
0 |
|
2300 |
53801591 |
caoash |
D |
May 5, 2019, 7:12 p.m. |
OK |
Java 8 |
TESTS |
73 |
218 |
0 |
|
2300 |
53649849 |
Java |
D |
May 1, 2019, 11:13 p.m. |
OK |
Java 8 |
TESTS |
73 |
234 |
0 |
|
2300 |
53649426 |
BiIIy |
D |
May 1, 2019, 10:35 p.m. |
OK |
Java 8 |
TESTS |
73 |
249 |
1331200 |
|
2300 |
53904870 |
hj5657 |
D |
May 9, 2019, 12:13 p.m. |
OK |
Java 8 |
TESTS |
73 |
249 |
17408000 |
|
2300 |
53707809 |
jst_forfun |
D |
May 3, 2019, 2:06 p.m. |
OK |
Java 8 |
TESTS |
73 |
280 |
0 |
|
2300 |
53637637 |
diego_93 |
D |
May 1, 2019, 4:15 p.m. |
OK |
Kotlin |
TESTS |
73 |
1310 |
128512000 |
|
2300 |
53963831 |
IleksaNott |
D |
May 10, 2019, 3:43 p.m. |
OK |
Mono C# |
TESTS |
73 |
280 |
9523200 |
|
2300 |
54638819 |
TrabajoNocturno |
D |
May 25, 2019, 6:21 p.m. |
OK |
Mono C# |
TESTS |
73 |
655 |
104243200 |
|
2300 |
53674170 |
omikad |
D |
May 2, 2019, 2:48 p.m. |
OK |
Mono C# |
TESTS |
73 |
732 |
163020800 |
|
2300 |
53673044 |
bbisnouse |
D |
May 2, 2019, 2:13 p.m. |
OK |
MS C++ |
TESTS |
73 |
93 |
7475200 |
|
2300 |
56711894 |
vjudge4 |
D |
July 8, 2019, 1:02 p.m. |
OK |
MS C++ |
TESTS |
73 |
124 |
4608000 |
|
2300 |
56711820 |
vjudge2 |
D |
July 8, 2019, 1 p.m. |
OK |
MS C++ |
TESTS |
73 |
124 |
22732800 |
|
2300 |
56713761 |
vjudge1 |
D |
July 8, 2019, 1:44 p.m. |
OK |
MS C++ |
TESTS |
73 |
139 |
20684800 |
|
2300 |
69172060 |
vjudge1 |
D |
Jan. 20, 2020, 6:34 a.m. |
OK |
MS C++ |
TESTS |
73 |
140 |
13516800 |
|
2300 |
69645832 |
vjudge5 |
D |
Jan. 28, 2020, 1:08 a.m. |
OK |
MS C++ |
TESTS |
73 |
140 |
16588800 |
|
2300 |
53723716 |
vjudge5 |
D |
May 4, 2019, 2:24 a.m. |
OK |
MS C++ |
TESTS |
73 |
155 |
15462400 |
|
2300 |
56875230 |
vjudge2 |
D |
July 12, 2019, 8:02 a.m. |
OK |
MS C++ |
TESTS |
73 |
155 |
17408000 |
|
2300 |
56706221 |
vjudge5 |
D |
July 8, 2019, 11:10 a.m. |
OK |
MS C++ |
TESTS |
73 |
186 |
37068800 |
|
2300 |
69171905 |
vjudge2 |
D |
Jan. 20, 2020, 6:30 a.m. |
OK |
MS C++ |
TESTS |
73 |
187 |
43622400 |
|
2300 |
54026429 |
Lordxx |
D |
May 12, 2019, 12:53 p.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
187 |
32051200 |
|
2300 |
53653426 |
zzq233 |
D |
May 2, 2019, 3:02 a.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
217 |
45363200 |
|
2300 |
53713564 |
CtrlAlt |
D |
May 3, 2019, 5:12 p.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
234 |
17305600 |
|
2300 |
53650631 |
petko_mitkov |
D |
May 2, 2019, 12:33 a.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
249 |
18636800 |
|
2300 |
53844716 |
hwangganzi |
D |
May 7, 2019, 10:05 a.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
264 |
12902400 |
|
2300 |
53697789 |
aigudada |
D |
May 3, 2019, 8:40 a.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
265 |
36147200 |
|
2300 |
53706368 |
Birdy_C |
D |
May 3, 2019, 1:23 p.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
483 |
7987200 |
|
2300 |
55221604 |
Pricolno |
D |
June 6, 2019, 8:01 p.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
499 |
18944000 |
|
2300 |
53678957 |
Timonnable |
D |
May 2, 2019, 5:47 p.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
546 |
18022400 |
|
2300 |
53640547 |
moreda |
D |
May 1, 2019, 4:38 p.m. |
OK |
MS C++ 2017 |
TESTS |
73 |
561 |
22425600 |
|
2300 |
53638409 |
pajenegod |
D |
May 1, 2019, 4:21 p.m. |
OK |
PyPy 2 |
TESTS |
73 |
342 |
15155200 |
|
2300 |
53715287 |
gatsko |
D |
May 3, 2019, 6:34 p.m. |
OK |
PyPy 2 |
TESTS |
73 |
982 |
114380800 |
|
2300 |
60081626 |
shanu_im |
D |
Sept. 5, 2019, 2:14 p.m. |
OK |
PyPy 2 |
TESTS |
73 |
1138 |
28774400 |
|
2300 |
53648063 |
pajenegod |
D |
May 1, 2019, 8:45 p.m. |
OK |
PyPy 2 |
TESTS |
73 |
1356 |
11264000 |
|
2300 |
53638526 |
cherry_su |
D |
May 1, 2019, 4:22 p.m. |
OK |
PyPy 2 |
TESTS |
73 |
1903 |
48537600 |
|
2300 |
53772954 |
FallingStar |
D |
May 5, 2019, 6:40 a.m. |
OK |
PyPy 3 |
TESTS |
73 |
716 |
46489600 |
|
2300 |
60321608 |
beginner1010 |
D |
Sept. 9, 2019, 8:52 p.m. |
OK |
PyPy 3 |
TESTS |
73 |
763 |
46592000 |
|
2300 |
63784396 |
wattaihei |
D |
Oct. 30, 2019, 11:55 a.m. |
OK |
PyPy 3 |
TESTS |
73 |
904 |
21504000 |
|
2300 |
53642217 |
Lisanaaa |
D |
May 1, 2019, 5:05 p.m. |
OK |
PyPy 3 |
TESTS |
73 |
1996 |
19660800 |
|
2300 |
53632513 |
nwi |
D |
May 1, 2019, 3:43 p.m. |
OK |
Python 2 |
TESTS |
73 |
873 |
23961600 |
|
2300 |
53713025 |
Helli.code |
D |
May 3, 2019, 4:46 p.m. |
OK |
Python 2 |
TESTS |
73 |
1700 |
56217600 |
|
2300 |
53648493 |
mgor |
D |
May 1, 2019, 9:17 p.m. |
OK |
Python 2 |
TESTS |
73 |
1950 |
56217600 |
|
2300 |
53772554 |
FallingStar |
D |
May 5, 2019, 6:27 a.m. |
OK |
Python 3 |
TESTS |
73 |
997 |
41472000 |
|
2300 |
53772294 |
FallingStar |
D |
May 5, 2019, 6:18 a.m. |
OK |
Python 3 |
TESTS |
73 |
1263 |
42291200 |
|
2300 |
53772228 |
FallingStar |
D |
May 5, 2019, 6:15 a.m. |
OK |
Python 3 |
TESTS |
73 |
1309 |
41472000 |
|
2300 |
53771739 |
FallingStar |
D |
May 5, 2019, 5:53 a.m. |
OK |
Python 3 |
TESTS |
73 |
1450 |
48844800 |
|
2300 |
53771617 |
FallingStar |
D |
May 5, 2019, 5:46 a.m. |
OK |
Python 3 |
TESTS |
73 |
1497 |
60416000 |
|
2300 |
53880098 |
Chizhonkova |
D |
May 8, 2019, 2:11 p.m. |
OK |
Python 3 |
TESTS |
73 |
1528 |
62156800 |
|
2300 |
53770424 |
FallingStar |
D |
May 5, 2019, 4:44 a.m. |
OK |
Python 3 |
TESTS |
73 |
1684 |
59699200 |
|
2300 |
54746228 |
kk17060123123 |
D |
May 28, 2019, 10:43 a.m. |
OK |
Python 3 |
TESTS |
73 |
1700 |
11468800 |
|
2300 |
53651567 |
Global_Elite |
D |
May 2, 2019, 1:38 a.m. |
OK |
Python 3 |
TESTS |
73 |
1825 |
20172800 |
|
2300 |
53720942 |
rennanrocha |
D |
May 3, 2019, 11:19 p.m. |
OK |
Python 3 |
TESTS |
73 |
1996 |
33689600 |
|
2300 |
55505510 |
kobae964 |
D |
June 12, 2019, 5:38 p.m. |
OK |
Rust |
TESTS |
73 |
280 |
18329600 |
|
2300 |
56761860 |
yakamoto |
D |
July 9, 2019, 4:15 p.m. |
OK |
Scala |
TESTS |
73 |
545 |
0 |
|
2300 |
remove filters
Back to search problems