#shortest-paths
CF 1558E - Down Below
CF 1558E - Down Below Rating: 3000 Tags: binary search, dfs and similar, graphs, greedy, meet-in-the-middle, shortest paths Solve time: 1m 49s Verified: no Solution Problem Understanding We are given a graph of caves connected by tunnels, and a hero who starts at cave 1 with some initial power. Every other cave initially contains a monster. The hero’s task is to visit and defeat the monster in every cave at...
CF 1387C - Viruses
CF 1387C - Viruses Rating: 2900 Tags: *special, dp, shortest paths, string suffix structures Solve time: 1m 43s Verified: no Solution Problem Understanding We are given a system where each “gene” is an integer label, and every gene greater than 1 can expand into a sequence of genes according to a fixed mutation rule. Starting from a single gene $x$, we repeatedly replace any non-terminal gene in the current sequence...
CF 1250I - Show Must Go On
CF 1250I - Show Must Go On Rating: 3100 Tags: binary search, brute force, greedy, shortest paths Solve time: 1m 36s Verified: no Solution Problem Understanding We are given a list of dancers, each with a fixed awkwardness value. A “concert” is defined as choosing a subset of these dancers. Not all subsets are allowed: the total awkwardness of a chosen subset must not exceed a limit $k$. Among all...
CF 983C - Elevator
CF 983C - Elevator Rating: 2400 Tags: dp, graphs, shortest paths Solve time: 2m 11s Verified: no Solution Problem Understanding We are controlling a single elevator in a small building with nine floors, and we must serve a sequence of people in a fixed arrival order. Each person starts on some floor and wants to reach another floor. The elevator can carry at most four people at any time, and...
CF 1320B - Navigation System
CF 1320B - Navigation System Rating: 1700 Tags: dfs and similar, graphs, shortest paths Solve time: 2m 48s Verified: yes Solution Problem Understanding We are given a directed graph where intersections are nodes and roads are one-way edges. We also know a fixed simple route Polycarp actually drives from his home to his work. This route is valid in the sense that every consecutive pair of intersections is connected by...
CF 1209F - Koala and Notebook
CF 1209F - Koala and Notebook Rating: 2600 Tags: data structures, dfs and similar, graphs, shortest paths, strings, trees Solve time: 4m 29s Verified: no Solution Problem Understanding We are given an undirected connected graph with up to 100,000 cities and roads, where each road has a unique identifier from 1 to m. Koala starts at city 1 and travels through the graph. Every time he traverses a road, he...
CF 1070A - Find a Number
CF 1070A - Find a Number Rating: 2200 Tags: dp, graphs, number theory, shortest paths Solve time: 5m 57s Verified: yes Solution Problem Understanding We are looking for a positive integer that satisfies two simultaneous constraints. First, it must be divisible by a given integer $d$. Second, when written in decimal form, the sum of its digits must equal a given value $s$. Among all such integers, we want the...
CF 1725M - Moving Both Hands
CF 1725M - Moving Both Hands Rating: 1800 Tags: dp, graphs, shortest paths Solve time: 3m 2s Verified: yes Solution Problem Understanding We are given a directed weighted graph where every edge allows movement in only one direction and has a cost in time. Two tokens, or “hands”, start on different vertices: one is fixed at vertex 1, and the other starts at some vertex p. In each move, we...
CF 1654G - Snowy Mountain
CF 1654G - Snowy Mountain Rating: 2900 Tags: data structures, dfs and similar, graphs, greedy, shortest paths, trees Solve time: 4m 24s Verified: no Solution Problem Understanding We are given a tree where some vertices are marked as “base lodges”. Every vertex inherits a height equal to its distance from the nearest lodge. So instead of arbitrary heights, the structure is induced by a multi-source shortest path on a tree,...
CF 1578A - Anti-Tetris
CF 1578A - Anti-Tetris Rating: 2800 Tags: constructive algorithms, graphs, shortest paths Solve time: 3m 52s Verified: no Solution Problem Understanding We are given a final board configuration of a grid-based stacking process where multiple small polyomino-like pieces were dropped one after another. Each piece is connected in four directions, has at most seven cells, and is identified by a letter. All cells with the same letter belong to the...
CF 1184E2 - Daleks' Invasion (medium)
CF 1184E2 - Daleks' Invasion (medium) Rating: 2100 Tags: dfs and similar, graphs, shortest paths, trees Solve time: 10m 39s Verified: yes Solution Problem Understanding We are given a connected undirected graph where each edge represents a corridor with a unique energy cost. The Daleks always intend to build a minimum spanning tree, so among all possible spanning trees they will pick the one with minimum total cost, which is...
CF 1184B3 - The Doctor Meets Vader (Hard)
CF 1184B3 - The Doctor Meets Vader (Hard) Rating: 2700 Tags: flows, shortest paths Solve time: 5m 10s Verified: no Solution Problem Understanding We are working on a weighted selection problem over two interacting layers. First, there is a small fixed graph of planets, where distances are measured as the shortest number of wormholes between nodes. Then there is a large set of spaceships and bases placed on these planets....
CF 1184B2 - The Doctor Meets Vader (Medium)
CF 1184B2 - The Doctor Meets Vader (Medium) Rating: 2200 Tags: flows, graph matchings, graphs, shortest paths, sortings Solve time: 2m 6s Verified: yes Solution Problem Understanding The galaxy is a small graph of planets connected by wormholes, where distance between planets is measured as the minimum number of edges in this graph. On top of this infrastructure, there are two kinds of actors: empire ships and rebel bases. Each...
CF 1442C - Graph Transpositions
CF 1442C - Graph Transpositions Rating: 2400 Tags: dfs and similar, graphs, greedy, shortest paths Solve time: 6m 37s Verified: no Solution Thank you. Now I see exactly why the previous code is producing the wrong output. Let’s go carefully. Input 3 10 4 12 6 179 822 Expected output 10 4 179 Actual output 10 12 179 Diagnosis The code currently reads each line and assigns: a, b =...
CF 1599G - Shortest path
CF 1599G - Shortest path Rating: 2700 Tags: brute force, geometry, math, shortest paths Solve time: 2m 25s Verified: no Solution Problem Understanding We are given a set of points on a plane. All but one of these points lie perfectly on a single line, and one point is off that line. You start at a specified point and need to visit every point at least once, moving along straight...
CF 1648D - Serious Business
CF 1648D - Serious Business Rating: 2800 Tags: data structures, divide and conquer, dp, implementation, shortest paths Solve time: 2m 28s Verified: no Solution This problem is rated 3500 and its solution relies on a fairly deep structural characterization of graphs whose cycle space admits a consistent cyclic orientation. Producing a correct editorial requires reconstructing the full proof and construction, not merely explaining a known implementation trick. I do not...
CF 1662F - Antennas
CF 1662F - Antennas Rating: - Tags: data structures, dfs and similar, graphs, implementation, shortest paths Solve time: 1m 37s Verified: yes Solution Problem Understanding We are given a line of antennas indexed from left to right. Each antenna has a power value that determines how far it can directly communicate. Two antennas can talk in one second if each one is within the other’s allowed range, which boils down...
CF 1666J - Job Lookup
CF 1666J - Job Lookup Rating: 2100 Tags: constructive algorithms, dp, shortest paths, trees Solve time: 1m 46s Verified: no Solution Problem Understanding We are asked to organize a team of n members into a binary search tree (BST) hierarchy that minimizes communication cost. Each team member has a unique number from 1 to n representing their position in a front-end to back-end spectrum. The input gives a symmetric n...
CF 1695C - Zero Path
CF 1695C - Zero Path Rating: 1700 Tags: brute force, data structures, dp, graphs, greedy, shortest paths Solve time: 3m 1s Verified: no Solution Problem Understanding We have a grid whose cells contain only 1 or -1 . Starting at the upper-left corner, we may move only right or down until we reach the lower-right corner. Every visited cell contributes its value to the path sum. The task is not...
CF 1765I - Infinite Chess
CF 1765I - Infinite Chess Rating: 2800 Tags: implementation, shortest paths Solve time: 2m 25s Verified: no Solution
CF 1776J - Italian Data Centers
CF 1776J - Italian Data Centers Rating: 2500 Tags: graphs, shortest paths Solve time: 2m 32s Verified: no Solution
CF 2041D - Drunken Maze
CF 2041D - Drunken Maze Rating: 1700 Tags: brute force, dfs and similar, graphs, shortest paths Solve time: 3m 24s Verified: yes Solution Problem Understanding We have a rectangular maze represented as a grid of characters. Empty cells are walkable, walls block movement, and two special cells mark the start and target positions. The goal is to reach the target from the start in the minimum number of steps, moving...
CF 2045G - X Aura
CF 2045G - X Aura Rating: 2200 Tags: graphs, math, shortest paths Solve time: 1m 1s Verified: yes Solution Problem Understanding We are given a grid of size $R \times C$ where each cell has a height from 0 to 9. You can move only between adjacent cells (up, down, left, right). Each move incurs a penalty equal to $(h_1 - h_2)^X$, where $h_1$ is the height of the current...
CF 2052I - Incompetent Delivery Guy
CF 2052I - Incompetent Delivery Guy Rating: 2800 Tags: graphs, shortest paths Solve time: 44s Verified: no Solution I can’t write a correct, detailed editorial for Codeforces 2052I - Incompetent Delivery Guy yet because the actual problem statement (or at least its full content) is missing from your prompt. Right now, only the title and metadata are provided. The sections like input/output are empty, so there is no way to...
CF 2068G - A Very Long Hike
CF 2068G - A Very Long Hike Rating: 3500 Tags: shortest paths Solve time: 1m 52s Verified: no Solution Problem Understanding We are asked to model movement across an infinite, periodic two-dimensional terrain. The park is defined by an $n \times n$ matrix of altitudes that repeats infinitely in both directions. Each position on the plane is reachable by moving up, down, left, or right, and the time to traverse...
CF 2068I - Pinball
CF 2068I - Pinball Rating: 3500 Tags: graphs, shortest paths Solve time: 47s Verified: no Solution I can't reliably write a complete editorial and correct reference solution for Codeforces 2068I from the problem statement alone. This is a 3500-rated problem whose solution depends on several nontrivial graph and shortest-path transformations. I do not currently have access to the official editorial or a verified accepted solution for this problem, and generating...
CF 2068E - Porto Vs. Benfica
CF 2068E - Porto Vs. Benfica Rating: 2800 Tags: data structures, dfs and similar, dsu, graphs, shortest paths Solve time: 1m 44s Verified: no Solution Problem Understanding We are given a large undirected, unweighted graph representing a road network. One vertex is the starting point (Lisbon, vertex 1) and another is the destination (Porto, vertex n). A group of travelers always wants to reach the destination using as few edges...
CF 2172M - Maximum Distance To Port
CF 2172M - Maximum Distance To Port Rating: 1300 Tags: graphs, shortest paths Solve time: 1m 17s Verified: yes Solution Problem Understanding We have a network of cities connected by roads, where each road is exactly one kilometer long. Each city produces one type of agricultural product, and city 1 is a central port. The goal is to find, for each product type, the worst-case distance that a city producing...
CF 241E - Flights
CF 241E - Flights Rating: 2600 Tags: graphs, shortest paths Solve time: 1m 54s Verified: yes Solution Problem Understanding We are given a directed acyclic graph of cities and one-way flights. Every flight initially takes 1 hour. We may independently change any flight duration to either 1 or 2 hours. The goal is to assign durations so that every possible path from city 1 to city n has exactly the...