ICPC 2018 - A. Catch the Plane
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/A-catch-the-plane. Edit
competitive_programming/icpc/2018/A-catch-the-plane/solution.tex to update the written solution and
competitive_programming/icpc/2018/A-catch-the-plane/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 A
Catch the Plane
Time limit: 10 seconds
Your plane to the ICPC Finals departs in a short time, and the only way to get to the airport is by bus.
Unfortunately, some of the bus drivers are considering going on strike, so you do not know whether
you can get to the airport on time. Your goal is to plan your journey in such a way as to maximize the
probability of catching your plane.
You have a detailed map of the city, which includes all the bus stations. You are at station 0 and the
airport is at station 1. You also have a complete schedule of when each bus leaves its start station and
arrives at its destination station. Additionally, for each bus you know the probability that it is actually
going to run as scheduled, as opposed to its driver going on strike and taking the bus out of service.
Assume all these events are independent. That is, the probability of a given bus running as planned does
not change if you know whether any of the other buses run as planned.
If you arrive before the departure time of a bus, you can transfer to that bus. But if you arrive exactly
at the departure time, you will not have enough time to get on the bus. You cannot verify ahead of time
whether a given bus will run as planned – you will find out only when you try to get on the bus. So if
two or more buses leave a station at the same time, you can try to get on only one of them.
Bus Schedule
Start Destination Departure Arrival
Station Station Time Time
20%
0 1 0 900
0 2 100 500
2 1 500 700
10%
2 1 501 701
0 3 200 50% 400
3 1 500 10% 800
3 0 550 90% 650
0 1 700 10% 900
Figure A.1: Bus schedule corresponding to Sample Input 1.
Consider the bus schedule shown in Figure A.1. It lists the start and destination stations of several bus
routes along with the departure and arrival times. You have written next to some of these the probability
that that route will run. Bus routes with no probability written next to them have a 100% chance of
running. You can try catching the first listed bus. If it runs, it will take you straight to the airport, and
you can stop worrying. If it does not, things get more tricky. You could get on the second listed bus to
station 2. It is certain to leave, but you would be too late to catch the third listed bus which otherwise
would have delivered you to the airport on time. The fourth listed bus – which you can catch – has only
a 0.1 probability of actually running. That is a bad bet, so it is better to stay at station 0 and wait for
the fifth listed bus. If you catch it, you can try to get onto the sixth listed bus to the airport; if that does
not run, you still have the chance of returning to station 0 and catching the last listed bus straight to the
airport.
Input
The first line of input contains two integers m (1 ≤ m ≤ 106 ) and n (2 ≤ n ≤ 106 ), denoting the number
of buses and the number of stations in the city. The next line contains one integer k (1 ≤ k ≤ 1018 ),
denoting the time by which you must arrive at the airport.
Each of the next m lines describes one bus. Each line contains integers a and b (0 ≤ a, b < n, a 6= b),
denoting the start and destination stations for the bus. Next are integers s and t (0 ≤ s < t ≤ k),
giving the departure time from station a and the arrival time at station b. The last value on the line is p
(0 ≤ p ≤ 1, with at most 10 digits after the decimal point), which denotes the probability that the bus
will run as planned.
Output
Display the probability that you will catch your plane, assuming you follow an optimal course of action.
Your answer must be correct to within an absolute error of 10−6 .
Sample Input 1 Sample Output 1
8 4 0.3124
1000
0 1 0 900 0.2
0 2 100 500 1.0
2 1 500 700 1.0
2 1 501 701 0.1
0 3 200 400 0.5
3 1 500 800 0.1
3 0 550 650 0.9
0 1 700 900 0.1
Sample Input 2 Sample Output 2
4 2 0.7
2
0 1 0 1 0.5
0 1 0 1 0.5
0 1 1 2 0.4
0 1 1 2 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
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\\A. Catch the Plane}
\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;
}