{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003eNote that this is the second problem of the two similar problems. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.\u003c/span\u003e\u003c/p\u003e\u003cp\u003eYou are given a tree with $$$n$$$ nodes. In the beginning, $$$0$$$ is written on all edges. In one operation, you can choose any $$$2$$$ distinct \u003cspan class\u003d\"tex-font-style-bf\"\u003eleaves\u003c/span\u003e $$$u$$$, $$$v$$$ and any \u003cspan class\u003d\"tex-font-style-bf\"\u003einteger\u003c/span\u003e number $$$x$$$ and add $$$x$$$ to values written on all edges on the simple path between $$$u$$$ and $$$v$$$. \u003cspan class\u003d\"tex-font-style-bf\"\u003eNote that in previous subtask $$$x$$$ was allowed to be any real, here it has to be integer\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eFor example, on the picture below you can see the result of applying two operations to the graph: adding $$$2$$$ on the path from $$$7$$$ to $$$6$$$, and then adding $$$-1$$$ on the path from $$$4$$$ to $$$5$$$. \u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/316536bd4b7aba35dd46c3074d24f1a3?v\u003d1714843196\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/center\u003e\u003cp\u003eYou are given some configuration of \u003cspan class\u003d\"tex-font-style-bf\"\u003enonnegative integer pairwise different even\u003c/span\u003e numbers, written on the edges. For a given configuration determine if it is possible to achieve it with these operations, and, if it is possible, output the sequence of operations that leads to the given configuration. Constraints on the operations are listed in the output format section.\u003c/p\u003e\u003cp\u003eLeave is a node of a tree of degree $$$1$$$. Simple path is a path that doesn\u0027t contain any node twice.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains a single integer $$$n$$$ ($$$2 \\le n \\le 1000$$$)\u0026nbsp;— the number of nodes in a tree.\u003c/p\u003e\u003cp\u003eEach of the next $$$n-1$$$ lines contains three integers $$$u$$$, $$$v$$$, $$$val$$$ ($$$1 \\le u, v \\le n$$$, $$$u \\neq v$$$, $$$0 \\le val \\le 10\\,000$$$), meaning that there is an edge between nodes $$$u$$$ and $$$v$$$ with $$$val$$$ written on it. It is guaranteed that these edges form a tree. It is guaranteed that all $$$val$$$ numbers are \u003cspan class\u003d\"tex-font-style-bf\"\u003epairwise different and even\u003c/span\u003e. \u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eIf there aren\u0027t any sequences of operations which lead to the given configuration, output \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eNO\u003c/span\u003e\".\u003c/p\u003e\u003cp\u003eIf it exists, output \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eYES\u003c/span\u003e\" in the first line. In the second line output $$$m$$$\u0026nbsp;— number of operations you are going to apply ($$$0 \\le m \\le 10^5$$$). \u003cspan class\u003d\"tex-font-style-bf\"\u003eNote that you don\u0027t have to minimize the number of the operations!\u003c/span\u003e\u003c/p\u003e\u003cp\u003eIn the next $$$m$$$ lines output the operations in the following format:\u003c/p\u003e\u003cp\u003e$$$u, v, x$$$ ($$$1 \\le u, v \\le n$$$, $$$u \\not \u003d v$$$, $$$x$$$\u0026nbsp;— integer, $$$-10^9 \\le x \\le 10^9$$$), where $$$u, v$$$\u0026nbsp;— leaves, $$$x$$$\u0026nbsp;— number we are adding. \u003c/p\u003e\u003cp\u003eIt is guaranteed that if there exists a sequence of operations producing given configuration, then there exists a sequence of operations producing given configuration, satisfying all the conditions above.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\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\u003e5\n1 2 2\n2 3 4\n3 4 10\n3 5 18\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eNO\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\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\u003e6\n1 2 6\n1 3 8\n1 4 12\n2 5 2\n2 6 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eYES\n4\n3 6 1\n4 6 3\n3 4 7\n4 5 2\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eThe configuration from the first sample is drawn below, and it is impossible to achieve.\u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/afec606bf3f3385bc48108e0f8f5b3ca?v\u003d1714843196\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/center\u003e\u003cp\u003eThe sequence of operations from the second sample is illustrated below.\u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/9c1def6fdec11eb821baf57cd1db8ff9?v\u003d1714843196\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/center\u003e"}}]}