All ICPC entries
Competitive Programming

ICPC 2018 - K. Wireless is the New Fiber

State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.

Source sync Apr 19, 2026
Track ICPC
Year 2018
Files TeX, C++, statement assets
Folder competitive_programming/icpc/2018/K-wireless-is-the-new-fiber
ICPC2018TeXC++statement textstatement pdf

Source-first archive entry

This page is built from the copied files in competitive_programming/icpc/2018/K-wireless-is-the-new-fiber. Edit competitive_programming/icpc/2018/K-wireless-is-the-new-fiber/solution.tex to update the written solution and competitive_programming/icpc/2018/K-wireless-is-the-new-fiber/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 K
                                   Wireless is the New Fiber
                                           Time limit: 2 seconds
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 Input 1                                       Sample Output 1
 7   11                                               3
 0   1                                                7   6
 0   2                                                0   1
 0   5                                                0   2
 0   6                                                0   5
 1   3                                                0   6
 2   4                                                3   6
 1   2                                                4   6
 1   2
 1   5
 2   6
 5   6

 Sample Input 2                                       Sample Output 2
 4   3                                                0
 0   1                                                4   3
 2   1                                                2   1
 2   3                                                1   3
                                                      0   2

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

  1. Describe the data structures and the state maintained by the algorithm.

  2. Explain the processing order and why it is sufficient.

  3. 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.

C++ competitive_programming/icpc/2018/K-wireless-is-the-new-fiber/solution.cpp

Exact copied implementation source.

Raw file
#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.

TeX write-up competitive_programming/icpc/2018/K-wireless-is-the-new-fiber/solution.tex

Exact copied write-up source.

Raw file
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}

\title{ICPC World Finals 2018\\K. Wireless is the New Fiber}
\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}