{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cp\u003eA long time ago in a galaxy far, far away, there were\n \u003cspan class\u003d\"tex2jax_process\"\u003e$N$\u003c/span\u003e planets. There were\n also \u003cspan class\u003d\"tex2jax_process\"\u003e$N - 1$\u003c/span\u003e\n interplanetary paths that connected all the planets (directly\n or indirectly). In other words, the network of planets and\n paths formed a tree. Additionally, each path was enumerated\n with an integer that denoted the curiosity of the path.\u003c/p\u003e\n\n \u003cp\u003eA pair of planets \u003cspan class\u003d\"tex2jax_process\"\u003e$A$\u003c/span\u003e,\n \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e is boring if the\n following holds:\u003c/p\u003e\n\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003e\u003cspan class\u003d\"tex2jax_process\"\u003e$A$\u003c/span\u003e and\n \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e are different\n planets;\u003c/p\u003e\n \u003c/li\u003e\n\n \u003cli\u003e\n \u003cp\u003etravelling between planet \u003cspan class\u003d\"tex2jax_process\"\u003e$A$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e is possible using one or more\n interplanetary paths; and\u003c/p\u003e\n \u003c/li\u003e\n\n \u003cli\u003e\n \u003cp\u003ethe binary XOR of the curiosity of all the paths in that\n travel is equal to 0\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n\n \u003cp\u003eAlas, the times have changed and an evil emperor is ruling\n the galaxy. He decided to use the Force to destroy all the\n interplanetary paths in a certain order. Determine the number\n of boring pairs of planets before the emperor started the\n destruction and after each destruction.\u003c/p\u003e\n\n \u003ch2\u003eInput\u003c/h2\u003e\n\n \u003cp\u003eThe first line of input contains the integer \u003cspan class\u003d\"tex2jax_process\"\u003e$N$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1\n \\leq N \\leq 100\\, 000$\u003c/span\u003e). Each of the following\n \u003cspan class\u003d\"tex2jax_process\"\u003e$N - 1$\u003c/span\u003e lines contains\n three integers \u003cspan class\u003d\"tex2jax_process\"\u003e$A_ i$\u003c/span\u003e,\n \u003cspan class\u003d\"tex2jax_process\"\u003e$B_ i$\u003c/span\u003e, \u003cspan class\u003d\"tex2jax_process\"\u003e$Z_ i$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\leq A_ i, B_ i \\leq N$\u003c/span\u003e,\n \u003cspan class\u003d\"tex2jax_process\"\u003e$0 \\leq Z_ i \\leq 1\\, 000\\, 000\\,\n 000$\u003c/span\u003e) that denote that planets \u003cspan class\u003d\"tex2jax_process\"\u003e$A_ i$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$B_ i$\u003c/span\u003e are directly connected with a\n path of curiosity \u003cspan class\u003d\"tex2jax_process\"\u003e$Z_ i$\u003c/span\u003e.\n The following line of input contains the permutation of the\n first \u003cspan class\u003d\"tex2jax_process\"\u003e$N - 1$\u003c/span\u003e integers\n that denote the order in which the emperor is destroying the\n paths. If the \u003cspan class\u003d\"tex2jax_process\"\u003e$i$\u003c/span\u003e-th\n element of the permutation is \u003cspan class\u003d\"tex2jax_process\"\u003e$j$\u003c/span\u003e, then the emperor destroyed the\n path between planets \u003cspan class\u003d\"tex2jax_process\"\u003e$A_\n j$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$B_ j$\u003c/span\u003e in\n the \u003cspan class\u003d\"tex2jax_process\"\u003e$i$\u003c/span\u003e-th step.\u003c/p\u003e\n\n \u003ch2\u003eOutput\u003c/h2\u003e\n\n \u003cp\u003eThe output must contain \u003cspan class\u003d\"tex2jax_process\"\u003e$N$\u003c/span\u003e lines, the \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e-th line containing the number of\n boring pairs A, \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e from\n the task after the emperor destroyed exactly \u003cspan class\u003d\"tex2jax_process\"\u003e$k - 1$\u003c/span\u003e paths.\u003c/p\u003e\n\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\n1 2 0\n1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\n0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n\n \u003ch2\u003eSample 2\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\n1 2 4\n2 3 4\n1 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\n0\n0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n\n \u003ch2\u003eSample 3\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\n1 2 0\n2 3 0\n2 4 0\n3 1 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\n3\n1\n0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}