All ICPC entries
Competitive Programming

ICPC 2014 - L. Wire Crossing

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 2014
Files TeX, C++, statement assets
Folder competitive_programming/icpc/2014/L-wire-crossing
ICPC2014TeXC++statement textstatement pdf

Source-first archive entry

This page is built from the copied files in competitive_programming/icpc/2014/L-wire-crossing. Edit competitive_programming/icpc/2014/L-wire-crossing/solution.tex to update the written solution and competitive_programming/icpc/2014/L-wire-crossing/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 L
                                          Wire Crossing
                                      Time Limit: 2 seconds
Moore’s Law states that the number of transistors on a chip will double every two years. Amazingly, this
law has held true for over half a century. Whenever current technology no longer allowed more growth,
researchers have come up with new manufacturing technologies to pack circuits even denser. In the near
future, this might mean that chips are constructed in three dimensions instead two. But for this problem,
two dimensions will be enough.
A problem common to all two-dimensional hardware design (for example chips, graphics cards, moth-
erboards, and so on) is wire placement. Whenever wires are routed on the hardware, it is problematic
if they have to cross each other. When a crossing occurs special gadgets have to be used to allow two
electrical wires to pass over each other, and this makes manufacturing more expensive.
Our problem is the following: you are given a hardware design with several wires already in place (all
of them straight line segments). You are also given the start and end points for a new wire connection
to be added. You will have to determine the minimum number of existing wires that have to be crossed
in order to connect the start and end points. This connection need not be a straight line. The only
requirement is that it cannot cross at a point where two or more wires already meet or intersect.

                                       Figure L.1: First sample input

Figure L.1 shows the first sample input. Eight existing wires form five squares. The start and end points
of the new connection are in the leftmost and rightmost squares, respectively. The black dashed line
shows that a direct connection would cross four wires, whereas the optimal solution crosses only two
wires (the curved blue line).

Input

The input consists of a single test case. The first line contains five integers m, x0 , y0 , x1 , y1 , which are
the number of pre-existing wires (m ≤ 100) and the start and end points that need to be connected.
This is followed by m lines, each containing four integers xa , ya , xb , yb describing an existing wire of
non-zero length from (xa , ya ) to (xb , yb ). The absolute value of each input coordinate is less than 105 .
Each pair of wires has at most one point in common, that is, wires do not overlap. The start and end
points for the new wire do not lie on a pre-existing wire.

Output

Display the minimum number of wires that have to be crossed to connect the start and end points.

 Sample Input 1                                     Sample Output 1
 8 3 3 19 3                                         2
 0 1 22 1
 0 5 22 5
 1 0 1 6
 5 0 5 6
 9 0 9 6
 13 0 13 6
 17 0 17 6
 21 0 21 6

 Sample Input 2                                     Sample Output 2
 1 0 5 10 5                                         0
 0 0 10 10

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/2014/L-wire-crossing/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/2014/L-wire-crossing/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 2014\\L. Wire Crossing Time Limit: 2 seconds}
\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}