{"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\u003eBwahahahahaha!!! Your nemesis, the dashingly handsome spy\n Waco Powers, has at last fallen to your secret volcano base’s\n deathtraps (or so you assume, being a little too busy to\n witness it firsthand). At long last, you are all set to\n \u003cspan class\u003d\"scshape\"\u003eConquer The World\u003c/span\u003e!\u003c/p\u003e\n \u003cp\u003eNothing will stand in your way! Well, nothing except a minor\n problem of logistics. Your evil armies have announced that they\n will not continue carving their relentless path of destruction\n across the puny nations of the world without being paid. And\n unfortunately you are running low on cash – a volcano lair has\n many wonderful qualities, but “reasonably affordable” is not\n one of them. You have had to pull funds from the travel budget\n to pay your ungrateful underlings. Now you are not sure how you\n will actually get your armies into position to \u003cspan class\u003d\"scshape\"\u003eConquer The World\u003c/span\u003e.\u003c/p\u003e\n \u003cp\u003eYou have a map of the nations of the world and all your\n available transport routes between them. Each route connects\n two nations and has a fixed cost per army that uses it. The\n routes are laid out such that there is exactly one way to\n travel between any two nations. You know the current position\n of each of your armies and how many you will need to place\n permanently in each nation in order to subjugate it. How can\n you move the armies into place as cheaply as possible so you\n can \u003cspan class\u003d\"scshape\"\u003eConquer The World\u003c/span\u003e?\u003c/p\u003e\n \u003ch2\u003eInput\u003c/h2\u003e\n \u003cp\u003eThe first line of input contains an integer \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1\n \\le n \\le 250\\, 000$\u003c/span\u003e), the number of nations. This is\n followed by \u003cspan class\u003d\"tex2jax_process\"\u003e$n-1$\u003c/span\u003e lines,\n each containing three integers \u003cspan class\u003d\"tex2jax_process\"\u003e$u$\u003c/span\u003e, \u003cspan class\u003d\"tex2jax_process\"\u003e$v$\u003c/span\u003e, and \u003cspan class\u003d\"tex2jax_process\"\u003e$c$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1\n \\le u, v \\le n$\u003c/span\u003e, \u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\le c\n \\le 10^6$\u003c/span\u003e), indicating that there is a bidirectional\n route connecting nations \u003cspan class\u003d\"tex2jax_process\"\u003e$u$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$v$\u003c/span\u003e, which costs \u003cspan class\u003d\"tex2jax_process\"\u003e$c$\u003c/span\u003e per army to use.\u003c/p\u003e\n \u003cp\u003eFinally, another \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e\n lines follow, the \u003cspan class\u003d\"tex2jax_process\"\u003e$i^{\\text\n {th}}$\u003c/span\u003e of which contains two non-negative integers\n \u003cspan class\u003d\"tex2jax_process\"\u003e$x_ i$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$y_ i$\u003c/span\u003e, indicating that there are\n currently \u003cspan class\u003d\"tex2jax_process\"\u003e$x_ i$\u003c/span\u003e armies in\n nation \u003cspan class\u003d\"tex2jax_process\"\u003e$i$\u003c/span\u003e, and you need\n at least \u003cspan class\u003d\"tex2jax_process\"\u003e$y_ i$\u003c/span\u003e armies to\n end up in that nation in the final configuration. The total\n number of armies (the sum of the \u003cspan class\u003d\"tex2jax_process\"\u003e$x_ i$\u003c/span\u003e values) is at least the sum of\n the \u003cspan class\u003d\"tex2jax_process\"\u003e$y_ i$\u003c/span\u003e values, and no\n more than \u003cspan class\u003d\"tex2jax_process\"\u003e$10^6$\u003c/span\u003e.\u003c/p\u003e\n \u003ch2\u003eOutput\u003c/h2\u003e\n \u003cp\u003eDisplay the minimum cost to move your armies such that there\n are at least \u003cspan class\u003d\"tex2jax_process\"\u003e$y_ i$\u003c/span\u003e armies\n in nation \u003cspan class\u003d\"tex2jax_process\"\u003e$i$\u003c/span\u003e for all\n \u003cspan class\u003d\"tex2jax_process\"\u003e$i$\u003c/span\u003e.\u003c/p\u003e\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\u003e3\n1 2 5\n3 1 5\n2 1\n5 0\n1 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e15\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\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\u003e6\n1 2 2\n1 3 5\n1 4 1\n2 5 5\n2 6 1\n0 0\n1 0\n2 1\n2 1\n0 1\n0 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e9\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}