ICPC 2018 - C. Conquer The World
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
Source-first archive entry
This page is built from the copied files in competitive_programming/icpc/2018/C-conquer-the-world. Edit
competitive_programming/icpc/2018/C-conquer-the-world/solution.tex to update the written solution and
competitive_programming/icpc/2018/C-conquer-the-world/solution.cpp to update the implementation.
The website does not replace those files with hand-maintained HTML. It reads the copied source tree during the build and exposes the exact files below.
Problem Statement
Copied statement text kept beside the solution archive for direct reference.
Problem C
Conquer The World
Time limit: 8 seconds
Bwahahahahaha!!! Your nemesis, the dashingly handsome spy Waco Powers, has at last fallen to your
secret volcano base’s deathtraps (or so you assume, being a little too busy to witness it firsthand). At
long last, you are all set to C ONQUER T HE W ORLD!
Nothing will stand in your way! Well, nothing except a minor problem of logistics. Your evil armies
have announced that they will not continue carving their relentless path of destruction across the puny
nations of the world without being paid. And unfortunately you are running low on cash – a volcano
lair has many wonderful qualities, but “reasonably affordable” is not one of them. You have had to pull
funds from the travel budget to pay your ungrateful underlings. Now you are not sure how you will
actually get your armies into position to C ONQUER T HE W ORLD.
You have a map of the nations of the world and all your available transport routes between them. Each
route connects two nations and has a fixed cost per army that uses it. The routes are laid out such that
there is exactly one way to travel between any two nations. You know the current position of each of
your armies and how many you will need to place permanently in each nation in order to subjugate it.
How can you move the armies into place as cheaply as possible so you can C ONQUER T HE W ORLD?
Input
The first line of input contains an integer n (1 ≤ n ≤ 250 000), the number of nations. This is followed
by n − 1 lines, each containing three integers u, v, and c (1 ≤ u, v ≤ n, 1 ≤ c ≤ 106 ), indicating that
there is a bidirectional route connecting nations u and v, which costs c per army to use.
Finally, another n lines follow, the ith of which contains two non-negative integers xi and yi , indicating
that there are currently xi armies in nation i, and you need at least yi armies to end up in that nation in
the final configuration. The total number of armies (the sum of the xi values) is at least the sum of the
yi values, and no more than 106 .
Output
Display the minimum cost to move your armies such that there are at least yi armies in nation i for all i.
Sample Input 1 Sample Output 1
3 15
1 2 5
3 1 5
2 1
5 0
1 3
Sample Input 2 Sample Output 2
6 9
1 2 2
1 3 5
1 4 1
2 5 5
2 6 1
0 0
1 0
2 1
2 1
0 1
0 1
Editorial
Rendered from the copied solution.tex file. The original TeX source remains
available below.
Key Observations
Write the structural observations that make the problem tractable.
State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
If the constraints matter, explain exactly which part of the solution they enable.
Algorithm
Describe the data structures and the state maintained by the algorithm.
Explain the processing order and why it is sufficient.
Mention corner cases explicitly if they affect the implementation.
Correctness Proof
We prove that the algorithm returns the correct answer.
Lemma 1.
State the first key claim.
Proof.
Provide a concise proof.
Lemma 2.
State the next claim if needed.
Proof.
Provide a concise proof.
Theorem.
The algorithm outputs the correct answer for every valid input.
Proof.
Combine the lemmas and finish the argument.
Complexity Analysis
State the running time and memory usage in terms of the input size.
Implementation Notes
Mention any non-obvious implementation detail that is easy to get wrong.
Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
Code
Exact copied C++ implementation from solution.cpp.
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Source Files
Exact copied source-of-truth files. Edit solution.tex for the write-up and solution.cpp for the implementation.
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}
\title{ICPC World Finals 2018\\C. Conquer The World}
\author{}
\date{}
\begin{document}
\maketitle
\section*{Problem Summary}
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
\section*{Key Observations}
\begin{itemize}[leftmargin=*]
\item Write the structural observations that make the problem tractable.
\item State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
\item If the constraints matter, explain exactly which part of the solution they enable.
\end{itemize}
\section*{Algorithm}
\begin{enumerate}[leftmargin=*]
\item Describe the data structures and the state maintained by the algorithm.
\item Explain the processing order and why it is sufficient.
\item Mention corner cases explicitly if they affect the implementation.
\end{enumerate}
\section*{Correctness Proof}
We prove that the algorithm returns the correct answer.
\paragraph{Lemma 1.}
State the first key claim.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Lemma 2.}
State the next claim if needed.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Theorem.}
The algorithm outputs the correct answer for every valid input.
\paragraph{Proof.}
Combine the lemmas and finish the argument.
\section*{Complexity Analysis}
State the running time and memory usage in terms of the input size.
\section*{Implementation Notes}
\begin{itemize}[leftmargin=*]
\item Mention any non-obvious implementation detail that is easy to get wrong.
\item Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
\end{itemize}
\end{document}
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}