K. Wireless is the New Fiber
A new type of unbounded-bandwidth wireless communication has just been tested and proved to be a suitable replacement for the existing, fiber-based communications network, which is struggling to keep up with traffic growth. You have been charged with decidi...
Problem Statement
Formatted from the contest statement text, with sample tests broken out into copyable blocks.
A new type of unbounded-bandwidth wireless communication has just been tested and proved to be a suitable replacement for the existing, fiber-based communications network, which is struggling to keep up with traffic growth. You have been charged with deciding the layout of the new communications network. The current communications network consists of a set of nodes (which route messages), and links of fiber, each of which connects two different nodes. For each pair of nodes, there exists at least one way (but possibly more, for bandwidth purposes) to travel along the fiber between the two. The new communications network will not have any fiber. Instead, it will have wireless links, each connecting two nodes. These links have unbounded bandwidth but are expensive, so it has been decided that as few of these links will be built as possible to provide connectivity; for each pair of nodes there should be exactly one way to travel between them along the wireless links. Moreover, you discovered that the nodes have each been built with a particular number of connections in mind. For each node, if it will be connected to a different number of links than it is today, it will have to be reorganized, and that is costly. Your task is to design the new network so that it has precisely one path between each pair of nodes while minimizing the number of nodes that do not have the same number of connections as in the original network. Figure K.1 shows the original network and a solution for Sample Input 1.
0 0
6 2 6 2
4 4
3 3
5 1 5 1
(a) The original fiber network. (b) One possible solution. The number of links has
changed for three nodes: 1, 2, and 5.
Figure K.1: Illustration of Sample Input 1.Input
The input begins with a line containing two integers n (2 ≤ n ≤ 104 ) and m (1 ≤ m ≤ 105 ), denoting the number of nodes and the number of fiber links in the existing network. The nodes are numbered from 0 to n − 1. Each of the next m lines contains two distinct integers ai and bi , denoting the fact that the ith fiber link connects nodes numbered ai and bi . It is guaranteed that for each pair of nodes there exists at least one path connecting the two nodes. Any pair of nodes may have more than one fiber link connecting them.
Output
Display the smallest number of nodes for which the number of connected links needs to change. Starting on the next line, display a system of connections in the same format as the input. That is, display a line containing the number of nodes (this will be the same as in the input) and the number of wireless links, and then on subsequent lines descriptions of the links. If more than one layout is possible, any valid layout will be accepted.
Sample Tests
7 11
0 1
0 2
0 5
0 6
1 3
2 4
1 2
1 2
1 5
2 6
5 6 3
7 6
0 1
0 2
0 5
0 6
3 6
4 6 4 3
0 1
2 1
2 3 0
4 3
2 1
1 3
0 2 Editorial
The solution write-up is rendered from the LaTeX source, with equations kept live through MathJax.
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
C++ solution used for this page.
#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 and Assets
Raw files are still available here when you want the original TeX, C++, or statement assets.
Show raw files
competitive_programming/icpc/2018/K-wireless-is-the-new-fiber/solution.texC++ implementationcompetitive_programming/icpc/2018/K-wireless-is-the-new-fiber/solution.cppStatement textcompetitive_programming/icpc/2018/K-wireless-is-the-new-fiber/statement.txtStatement PDFcompetitive_programming/icpc/2018/K-wireless-is-the-new-fiber/statement.pdfMetadatacompetitive_programming/icpc/2018/K-wireless-is-the-new-fiber/meta.jsonYear packetcompetitive_programming/icpc/2018/contest_problems.pdf