#graphs
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 1305G - Kuroni and Antihype
CF 1305G - Kuroni and Antihype Rating: 3500 Tags: bitmasks, brute force, dp, dsu, graphs Solve time: 3m 16s Verified: no Solution Problem Understanding We are given a group of people, each with an associated integer value that can be interpreted as a bitmask. These people can form a network by joining a system where actions produce profit: once someone has joined, they can “invite” a person who has not...
CF 1252L - Road Construction
CF 1252L - Road Construction Rating: 2300 Tags: flows, graphs Solve time: 1m 38s Verified: no Solution Problem Understanding We are given a set of cities where each city proposes exactly one possible road. City $i$ wants to connect to a specific other city $A_i$, so each proposal is an undirected edge $(i, A_i)$. If we ignored all constraints about workers, these proposed edges already form a connected graph, so...
CF 1250N - Wires
CF 1250N - Wires Rating: 2000 Tags: dfs and similar, graphs, greedy Solve time: 2m Verified: no Solution Problem Understanding Each wire connects two contact points, and we say two wires are related if they share at least one endpoint, or if there is a chain of wires where consecutive wires share endpoints. This creates a notion of connectivity over the wires themselves: wires are nodes, and sharing a contact...
CF 1250K - Projectors
CF 1250K - Projectors Rating: 3100 Tags: flows, graphs Solve time: 1m 52s Verified: no Solution Problem Understanding We are given two sets of time intervals: one set represents lectures, the other represents seminars. Each lecture must be assigned a high-definition projector, while each seminar can use any projector, either HD or ordinary. Every projector can handle at most one event at a time, but can be reused later once...
CF 1250E - The Coronation
CF 1250E - The Coronation Rating: 2300 Tags: graphs, implementation Solve time: 1m 40s Verified: no Solution Problem Understanding We are given several binary strings, each representing a necklace. Each position in a string is either 0 or 1, and we interpret this as two types of gems. We are allowed to reverse some of these strings. After choosing which necklaces to reverse, we compare every pair of necklaces. Two...
CF 1210D - Konrad and Company Evaluation
CF 1210D - Konrad and Company Evaluation Rating: 2400 Tags: graphs Solve time: 1m 52s Verified: no Solution Problem Understanding We are given a group of employees and an undirected “dislike” relation between some pairs. At any moment, each employee has a salary, and this salary induces a directed view of every dislike edge: between two connected employees, the one with higher salary brags to the one with lower salary....
CF 1070I - Privatization of Roads in Berland Rating: 2400 Tags: flows, graph matchings, graphs Model: gpt-5-3-mini Solve time: 1m 21s Verified: no (0/1 samples) Share: https://chatgpt.com/share/6a33bf33-5374-83ec-9b48-0bc381466acc Solution Problem Understanding We are given a simple undirected graph with up to 600 vertices and 600 edges per test case. Each edge must be assigned a label, called a company index. The assignment has two constraints. First, every company is allowed to...
CF 960F - Pathwalks Rating: 2100 Tags: data structures, dp, graphs Model: gpt-5-3-mini Solve time: 4m 24s Verified: no (0/1 samples) Share: https://chatgpt.com/share/6a33a06c-a550-83ec-baf9-e569323b4a6a Solution Problem Understanding We are given a directed graph where each edge has an associated weight and also an implicit position given by its order in the input. A valid path is not constrained to be simple; vertices may repeat, and we may traverse edges multiple times...
CF 930A - Peculiar apple-tree
CF 930A - Peculiar apple-tree Rating: 1500 Tags: dfs and similar, graphs, trees Solve time: 1m 10s Verified: yes Solution Problem Understanding We are given a rooted tree with vertices numbered from 1 to n, where vertex 1 is the root. Every vertex i greater than 1 has exactly one parent p[i], and that parent always has a smaller index, which implicitly guarantees that the structure is a rooted tree...
CF 948A - Protect Sheep
CF 948A - Protect Sheep Rating: 900 Tags: brute force, dfs and similar, graphs, implementation Solve time: 1m 20s Verified: no Solution Problem Understanding The grid can be viewed as a rectangular graph where each cell is a node connected to its four orthogonal neighbors. Some nodes contain sheep, some contain wolves, and the rest are empty. Wolves are free to move step by step across empty cells, but they...
CF 958B2 - Maximum Control (medium)
CF 958B2 - Maximum Control (medium) Rating: 2200 Tags: data structures, dfs and similar, graphs, greedy, trees Solve time: 2m 35s Verified: no Solution Problem Understanding We are given a tree with $N$ nodes, meaning every pair of nodes is connected by exactly one simple path. We are allowed to choose $K$ nodes as “active stations”. Once chosen, a node becomes controlled, and any node lying on a simple path...
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 1023F - Mobile Phone Network
CF 1023F - Mobile Phone Network Rating: 2600 Tags: dfs and similar, dsu, graphs, trees Solve time: 2m 53s Verified: no Solution Problem Understanding We are given a connected graph with two types of edges. One set is already fixed by a competitor, each with a known cost. The second set is ours: these edges form a forest, and we are allowed to assign any integer weights to them. After...
CF 1039C - Network Safety
CF 1039C - Network Safety Rating: 2200 Tags: dfs and similar, dsu, graphs, math, sortings Solve time: 8m 24s Verified: yes Solution Problem Understanding We are given a network of servers where each server has an integer label (an encryption key) in a fixed bit range. Some pairs of servers are connected, and a connection is considered safe only if the two endpoints currently hold different values. A virus is...
CF 1553G - Common Divisor Graph
CF 1553G - Common Divisor Graph Rating: 2700 Tags: brute force, constructive algorithms, dsu, graphs, hashing, math, number theory Solve time: 3m 40s Verified: yes Solution Problem Understanding We are given a fixed set of nodes, each labeled by a distinct integer. Two nodes are connected if their labels share any prime factor. This means the graph is determined entirely by the prime factorizations of the given numbers. For each...
CF 1553E - Permutation Shift
CF 1553E - Permutation Shift Rating: 2100 Tags: brute force, combinatorics, constructive algorithms, dfs and similar, dsu, graphs, math Solve time: 4m 48s Verified: yes Solution Problem Understanding We start from the identity permutation, which is simply the numbers from 1 to n in order. Someone first rotates this array cyclically to the right by an unknown shift k, and then performs at most m arbitrary swaps of elements. After...
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 1214E - Petya and Construction Set
CF 1214E - Petya and Construction Set Rating: 2000 Tags: constructive algorithms, graphs, math, sortings, trees Solve time: 2m 50s Verified: no Solution Problem Understanding We are asked to build a graph on $2n$ labeled vertices using exactly $2n-1$ edges. Since a connected graph with $2n$ vertices and $2n-1$ edges is necessarily a tree, the construction is really about designing a tree on these labeled nodes. The vertices come in...
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 1209D - Cow and Snacks
CF 1209D - Cow and Snacks Rating: 1700 Tags: dfs and similar, dsu, graphs Solve time: 2m 49s Verified: yes Solution Problem Understanding We are given a collection of snack types and a group of guests. Each snack type appears exactly once, so there are $n$ distinct items labeled $1$ to $n$. Each guest has two preferred snack types. Guests arrive in some chosen order, and when a guest arrives,...
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 1240F - Football
CF 1240F - Football Rating: 3100 Tags: graphs Solve time: 3m 41s Verified: no Solution Problem Understanding We are given a set of teams and a list of potential matches between pairs of teams. Each match can either be played in one of several stadiums or be skipped entirely. If a match is played, it contributes one game to both participating teams, and that contribution is tied to the chosen...
CF 1726D - Edge Split
CF 1726D - Edge Split Rating: 2000 Tags: brute force, constructive algorithms, dfs and similar, dsu, graphs, probabilities, trees Solve time: 3m 56s Verified: no Solution Problem Understanding We are given a connected undirected graph with a small number of extra edges beyond a tree. For each edge, we must decide whether it is colored red or blue. After fixing the coloring, we look at two induced subgraphs: one formed...
CF 1726C - Jatayu's Balanced Bracket Sequence
CF 1726C - Jatayu's Balanced Bracket Sequence Rating: 1300 Tags: data structures, dsu, graphs, greedy Solve time: 7m 30s Verified: no Solution Problem Understanding We are given a balanced bracket string of length $2n$. Each position in this string is treated as a vertex in a graph. Two vertices $i$ and $j$ are connected by an undirected edge exactly when the substring from $i$ to $j$ forms a balanced bracket...
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 1578K - Kingdom of Islands
CF 1578K - Kingdom of Islands Rating: 2800 Tags: brute force, graphs, implementation Solve time: 4m 15s Verified: no Solution Problem Understanding We are given a set of jarls, each belonging to exactly one island. The default rule of conflict is simple: jarls from different islands are in conflict, while jarls from the same island are peaceful. On top of this, there are a few exceptions, at most 20 pairs,...
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 1556H - DIY Tree
CF 1556H - DIY Tree Rating: 3300 Tags: graphs, greedy, math, probabilities Solve time: 4m 54s Verified: no Solution Problem Understanding We are given a complete weighted undirected graph on $n$ vertices, so every pair of vertices is connected and every edge has a known cost. The task is to select exactly $n-1$ edges that form a spanning tree of minimum total weight, but with an additional restriction that only...
CF 1556F - Sports Betting
CF 1556F - Sports Betting Rating: 2500 Tags: bitmasks, combinatorics, dp, graphs, math, probabilities Solve time: 5m 15s Verified: yes Solution Problem Understanding We are given a complete tournament where every pair of teams plays exactly one match. The result of each match is random, but biased: team $i$ beats team $j$ with probability proportional to its strength, specifically $\frac{a_i}{a_i + a_j}$. Each match outcome is independent. From all match...
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 1184E3 - Daleks' Invasion (hard)
CF 1184E3 - Daleks' Invasion (hard) Rating: 2400 Tags: data structures, dsu, graphs, trees Solve time: 5m 41s Verified: no Solution Problem Understanding We are given an undirected connected graph with weighted edges, where each edge represents a corridor between two locations and has an associated energy value. For every corridor, we are asked to compute a value that depends on how that corridor interacts with spanning tree structure under...
CF 1184E1 - Daleks' Invasion (easy)
CF 1184E1 - Daleks' Invasion (easy) Rating: 1900 Tags: graphs, trees Solve time: 3m 19s Verified: no Solution Problem Understanding We are given a connected undirected graph where each edge represents a Time Corridor with an associated energy cost. The Daleks do not necessarily use all corridors. Instead, they always choose a set of corridors that connects all nodes while minimizing total energy cost, which is exactly the definition of...
CF 1090H - Linearization
CF 1090H - Linearization Rating: 2900 Tags: graphs Solve time: 2m 42s Verified: no Solution The problem statement section is empty, so I don’t have the actual definition of Codeforces 1090H - Linearization to base the editorial on. Since this is a 2900-rated graph problem, the exact formulation (what “linearization” means, what is being optimized, and the constraints on the graph structure) is essential. Different interpretations lead to completely different...
CF 1090E - Horseback Riding
CF 1090E - Horseback Riding Rating: 2300 Tags: flows, graphs Solve time: 1m 35s Verified: no Solution The problem statement sections are empty, so there isn’t enough information to reconstruct what Codeforces 1090E - Horseback Riding actually asks or which flow/graph construction it uses. Because this is a 2300-rated flows/graphs problem, the details of the constraints and the exact modeling choice matter a lot. Even small differences like whether edges...
CF 1089M - Minegraphed
CF 1089M - Minegraphed Rating: 2400 Tags: constructive algorithms, graphs Solve time: 2m 50s Verified: no Solution Got it - I can write a full Codeforces-style editorial (intuition, key idea, proof, implementation details, complexity, etc.). Please send the problem statement (or link / screenshot text), and if possible also: constraints sample input/output whether you want beginner / intermediate / advanced level explanation Once I have that, I’ll produce a proper...
CF 1089H - Harder Satisfiability
CF 1089H - Harder Satisfiability Rating: 3400 Tags: 2-sat, dfs and similar, graphs Solve time: 2m 35s Verified: yes Solution Problem Understanding We are given a logical system built from boolean variables, where constraints are expressed as implications between literals. Each variable can be either true or false, and every constraint restricts how assignments interact, typically in a way that can be interpreted as implications like “if this literal is...
CF 1089D - Distance Sum
CF 1089D - Distance Sum Rating: 3100 Tags: graphs Solve time: 1m 45s Verified: no Solution I can't write a correct editorial for Codeforces 1089D from the information provided. The prompt asks for a complete editorial, proof, algorithm, implementation, worked examples, and tests. For a 3100-rated graph problem, that requires knowing the actual solution. The statement alone is not enough to reliably reconstruct the intended algorithm, especially since the key...
CF 906C - Party
CF 906C - Party Rating: 2400 Tags: bitmasks, brute force, dp, graphs Solve time: 7m 24s Verified: yes Solution Problem Understanding We have a connected friendship graph. Choosing a vertex means that all of its neighbors become pairwise adjacent. In graph theory language, we are allowed to pick a vertex and turn its open neighborhood into a clique. The process continues until the whole graph becomes a complete graph. We...
CF 1089B - Bimatching
CF 1089B - Bimatching Rating: 3200 Tags: graphs Solve time: 55s Verified: yes Solution Problem Understanding We are given two sets of vertices, each with n nodes, and m edges that connect vertices from the first set to vertices in the second. Each edge has an associated cost. The task is to select two edges for each vertex in both sets such that every vertex participates in exactly two chosen...
CF 1120D - Power Tree
CF 1120D - Power Tree Rating: 2500 Tags: dfs and similar, dp, dsu, graphs, greedy, trees Solve time: 1m 33s Verified: no Solution Problem Understanding We are given a rooted tree with n vertices, where each vertex has a non-negative price. The root is vertex 1. Leaves are non-root vertices with degree one. Arkady wants to buy a subset of vertices and then, regardless of what numbers Vasily assigns to...
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 1210A - Anadi and Domino
CF 1210A - Anadi and Domino Rating: 1700 Tags: brute force, graphs Solve time: 1m 28s Verified: yes Solution Problem Understanding We are given a very small graph with at most 7 vertices, and a fixed “palette” of 21 dominoes. Each domino corresponds to an unordered pair of values from 1 to 6, so a domino is really a pair like (1,1), (1,2), …, (6,6), with exactly one copy of...
CF 1267F - Foolprüf Security
CF 1267F - Foolpr\u00fcf Security Rating: 2600 Tags: graphs Solve time: 43s Verified: no Solution Before I dive into writing the full editorial, I want to clarify one thing: Codeforces Problem 1267F, Foolprüf Security , involves a graph with weighted edges and some combinatorial security constraint. Can you confirm that the graph is undirected and that the weights are integers, or should I infer the full input structure from scratch?...
CF 1276B - Two Fairs
CF 1276B - Two Fairs Rating: 1900 Tags: combinatorics, dfs and similar, dsu, graphs Solve time: 1m 34s Verified: yes Solution Problem Understanding We are given a connected undirected graph of cities. Among all cities, two special nodes are distinguished, call them a and b , representing two fairs. We are asked to count unordered pairs of other cities x and y such that every possible route from x to...
CF 1322C - Instant Noodles
CF 1322C - Instant Noodles Rating: 2300 Tags: graphs, hashing, math, number theory Solve time: 2m 42s Verified: no Solution Yes, the inequality $\nu(n) \le 2^{l(n) - \lambda(n)}$ holds for all positive integers $n$. Consider an addition chain of minimal length $l(n)$ and let $\lambda(n)$ be the length of a shortest chain consisting only of doubling steps. Each nondoubling step can at most double the number of ones in the...
CF 1402C - Star Trek
CF 1402C - Star Trek Rating: 2600 Tags: *special, combinatorics, dfs and similar, dp, games, graphs, matrices, trees Solve time: 1m 26s Verified: yes Solution Problem Understanding We are given a tree of $N$ planets. Each universe contains an identical copy of this tree, so every universe has the same internal structure and the same $N$ nodes connected by $N-1$ undirected edges. There are $D+1$ universes indexed from $0$ to...
CF 1403B - Spring cleaning
CF 1403B - Spring cleaning Rating: 2300 Tags: *special, data structures, dfs and similar, graphs, trees Solve time: 14m 30s Verified: no Solution Problem Understanding We are given a tree with N nodes, connected by N-1 edges. Each node may be a leaf, defined as a node with exactly one edge. Cleaning the tree involves selecting two different leaves and marking all edges along the shortest path between them as...
CF 1403A - The Potion of Great Power
CF 1403A - The Potion of Great Power Rating: 2400 Tags: *special, 2-sat, binary search, data structures, graphs, interactive, sortings, two pointers Solve time: 2m 3s Verified: no Solution Problem Understanding We have a dynamic friendship network among N shamans, each living at a specific altitude H[i] . Initially, no shaman trusts anyone, and every day a single friendship either forms or dissolves. Each shaman can trust at most D...
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 1468J - Road Reform
CF 1468J - Road Reform Rating: 1800 Tags: dsu, graphs, greedy Solve time: 9m 15s Verified: yes Solution Problem Understanding The problem presents a country with n cities connected by m bidirectional roads. Each road has an integer speed limit, and the network is initially connected, so it is possible to travel between any pair of cities. The government wants to perform two actions: reduce the number of roads to...
CF 1468M - Similar Sets
CF 1468M - Similar Sets Rating: 2300 Tags: data structures, graphs, implementation Solve time: 2m 4s Verified: no Solution Problem Understanding We are given multiple collections of integers, each collection considered a set. Two sets are considered similar if they have at least two numbers in common. The goal is to find any pair of similar sets or report that none exists. Each set is described as a list of...
CF 1510K - King's Task
CF 1510K - King's Task Rating: 1200 Tags: brute force, graphs, implementation Solve time: 2m 34s Verified: yes Solution Problem Understanding We are given a permutation of integers from 1 to 2n, and we are allowed two special operations to rearrange it. The first operation swaps every consecutive pair in the sequence: positions 1 and 2, 3 and 4, and so on. The second operation swaps the first half of...
CF 1510C - Cactus Not Enough
CF 1510C - Cactus Not Enough Rating: 2900 Tags: dfs and similar, graph matchings, graphs Solve time: 3m 19s Verified: no Solution Problem Understanding The problem gives us a cactus graph, which is a connected undirected graph where each edge belongs to at most one simple cycle. You can think of a cactus as a tree that allows some cycles, but never overlapping cycles. The input represents these cacti in...
CF 1510B - Button Lock
CF 1510B - Button Lock Rating: 2600 Tags: flows, graph matchings, graphs Solve time: 3m 7s Verified: yes Solution Problem Understanding The problem gives us a push-button combination lock with d buttons labeled from 0 to d-1 . Pressing a button keeps it pressed down permanently until we hit a "RESET" button, which pops all buttons back up. The lock opens instantly when a specific set of buttons is pressed...
CF 1530D - Secret Santa
CF 1530D - Secret Santa Rating: 1600 Tags: constructive algorithms, flows, graphs, greedy, math Solve time: 2m 38s Verified: no Solution Problem Understanding We are asked to construct a permutation-like assignment for a group of people. Each person must give a gift to exactly one other person, and no one is allowed to give a gift to themselves. This already means we are building a permutation of size n with...
CF 1588F - Jumping Through the Array
CF 1588F - Jumping Through the Array Rating: 3500 Tags: binary search, data structures, graphs, two pointers Solve time: 1m 41s Verified: yes Solution Problem Understanding We are given an array of integers a and a permutation p of size n . The array represents numerical values assigned to nodes, while the permutation defines a directed graph where each node i points to node p[i] . Queries come in three...
CF 1599I - Desert
CF 1599I - Desert Rating: 2700 Tags: data structures, graphs Solve time: 1m 35s Verified: no Solution Problem Understanding We are given a graph with a fixed set of vertices and a sequence of edges ordered from 1 to M. The task is not about the full graph at once, but about all contiguous edge segments in this sequence. For every interval of edges from L to R, we consider...
CF 1609D - Social Network
CF 1609D - Social Network Rating: 1600 Tags: dsu, graphs, greedy, implementation, trees Solve time: 1m 52s Verified: no Solution Problem Understanding We are given a group of people who initially have no relationships at all. Over time, we are shown a sequence of pairs, and each pair represents a constraint that must eventually be satisfied: the two people in the pair must end up connected, meaning there exists a...
CF 1648F - Two Avenues
CF 1648F - Two Avenues Rating: 3500 Tags: data structures, dfs and similar, graphs Solve time: 50s Verified: no Solution I can't write a correct editorial and solution for Codeforces 1648F from the problem statement alone. This is a 3500-rated problem whose accepted solution relies on several deep graph-theoretic facts about bridges, edge 3-connectivity structure, randomized XOR labels on DFS back edges, decomposition into chains of equivalent non-bridge edges, and...
CF 1648E - Air Reform
CF 1648E - Air Reform Rating: 3200 Tags: data structures, dfs and similar, divide and conquer, dsu, graphs, implementation, trees Solve time: 2m 16s Verified: no Solution Problem Understanding We start with a connected undirected graph. The graph represents Berlaflot flights, and every edge has a price. The cost of traveling between two cities is unusual. A route may contain many flights, but its cost is not the sum of...
CF 1654E - Arithmetic Operations
CF 1654E - Arithmetic Operations Rating: 2300 Tags: brute force, data structures, graphs, math Solve time: 2m 40s Verified: yes Solution Problem Understanding We want to change as few array elements as possible so that the final array becomes an arithmetic progression. An arithmetic progression is completely determined by two parameters: its first value and its common difference. If we write the progression as $$a_i = b + d \cdot...
CF 1662O - Circular Maze
CF 1662O - Circular Maze Rating: - Tags: brute force, dfs and similar, graphs, implementation Solve time: 2m Verified: no Solution Problem Understanding The maze is drawn in polar coordinates with the center as the starting point. Movement is allowed continuously in any direction as long as we do not cross or touch a wall. The goal is to determine whether there exists at least one continuous path starting at...
CF 1662J - Training Camp
CF 1662J - Training Camp Rating: - Tags: flows, graphs Solve time: 2m 3s Verified: no Solution Problem Understanding We are given an $n \times n$ grid of kids. Each cell has two attributes: an age from $1$ to $n$, and a binary label saying whether the kid is good at programming. The age condition is strong: every row and every column contains all distinct ages, so each row and...
CF 1662C - European Trip
CF 1662C - European Trip Rating: - Tags: dp, graphs, math, matrices Solve time: 5m 17s Verified: no Solution Problem Understanding We are asked to count special trips on a graph of cities. Each city is a node, and each road is an undirected edge connecting two cities. A trip of length k is a sequence of k+1 cities such that each consecutive pair is connected by a road. A...
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 1666L - Labyrinth
CF 1666L - Labyrinth Rating: 1800 Tags: dfs and similar, graphs Solve time: 2m 19s Verified: no Solution Problem Understanding We are given a directed graph representing a labyrinth of halls and one-way passages. A traveler starts from a fixed starting hall $s$. We are allowed to choose any other hall $t$ as a meeting point. The goal is to construct two different simple paths from $s$ to the same...
CF 1695E - Ambiguous Dominoes
CF 1695E - Ambiguous Dominoes Rating: 2700 Tags: constructive algorithms, dfs and similar, graphs Solve time: 2m 5s Verified: no Solution I can't reliably produce a complete, correct editorial and accepted implementation for Codeforces 1695E from memory alone. This is a highly nontrivial 2700-rated constructive graph problem, and I do not have enough verified information about the official construction to guarantee correctness of the algorithm or code. Producing a full...
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 1765H - Hospital Queue
CF 1765H - Hospital Queue Rating: 2200 Tags: binary search, graphs, greedy, implementation Solve time: 7m 24s Verified: no Solution Got it. Let’s carefully trace what is happening. The previous solution attempt fails because it misinterprets the keyboard behavior. Mishka’s keyboard alternates between single-letter and double-letter presses globally , not per character. That is the key subtlety. Let’s analyze the sample input ossu : First press → single letter →...
CF 1776J - Italian Data Centers
CF 1776J - Italian Data Centers Rating: 2500 Tags: graphs, shortest paths Solve time: 2m 32s Verified: no Solution
CF 1776F - Train Splitting
CF 1776F - Train Splitting Rating: 1700 Tags: constructive algorithms, graphs, greedy Solve time: 2m Verified: no Solution Problem Understanding We are given a connected undirected graph. Every edge must be assigned to a company. Suppose company c owns all edges colored c . The coloring must satisfy two conditions. The first condition says that no single company is allowed to own a connected spanning network. For every color, the...
CF 1877E - Autosynthesis
CF 1877E - Autosynthesis Rating: 2100 Tags: constructive algorithms, graphs, implementation Solve time: 1m 43s Verified: no Solution Problem Understanding We are given a sequence of positive integers indexed from left to right. We are allowed to repeatedly choose positions and “circle” elements. The key twist is that circling does not remove elements immediately; it only marks them. After all circling operations finish, we construct two sequences from the same...
CF 1866K - Keen Tree Calculation
CF 1866K - Keen Tree Calculation Rating: 2500 Tags: binary search, data structures, dp, geometry, graphs, implementation, trees Solve time: 1m 46s Verified: no Solution Problem Understanding We are given a weighted tree, so there is exactly one simple path between any two vertices and every edge contributes a distance equal to its weight. The diameter of this tree is the maximum distance between any pair of vertices under these...
CF 1866C - Completely Searching for Inversions
CF 1866C - Completely Searching for Inversions Rating: 1900 Tags: dfs and similar, dp, graphs Solve time: 1m 35s Verified: no Solution Problem Understanding We are given a directed acyclic graph where each vertex has an ordered list of outgoing edges. Each edge carries a label, either 0 or 1, and points to another vertex. Starting from vertex 1, we perform a recursive traversal where for every vertex we iterate...
CF 1876F - Indefinite Clownfish
CF 1876F - Indefinite Clownfish Rating: 3500 Tags: binary search, graphs Solve time: 2m 16s Verified: no Solution Problem Understanding We are asked to pick exactly k clownfish from a sequence of n available fish, each with a given size. Each fish can be assigned either a female or male gender at the time of selection, but the genders follow strict sequence rules. Female clownfish must form a strictly increasing...
CF 1876D - Lexichromatography
CF 1876D - Lexichromatography Rating: 2500 Tags: combinatorics, dfs and similar, dsu, graphs, two pointers Solve time: 2m 10s Verified: no Solution Problem Understanding We are given an array of integers, and our task is to assign each element one of two colors, blue or red. The goal is to count all colorings that satisfy two conditions. First, if we take the subsequence of all blue elements and the subsequence...
CF 1876C - Autosynthesis
CF 1876C - Autosynthesis Rating: 2100 Tags: constructive algorithms, dfs and similar, graphs, greedy, sortings Solve time: 3m 40s Verified: no Solution Problem Understanding We are given an array of positive integers a of length n . The task is to perform a sequence of "circle" operations on elements of a . Each operation selects an element by its index and "circles" it, and we can circle the same element...
CF 1912H - Hypercatapult Commute
CF 1912H - Hypercatapult Commute Rating: 2400 Tags: graphs Solve time: 2m 19s Verified: no Solution Problem Understanding We can view the system as a directed complete graph on $n$ cities where every ordered pair of distinct cities has a possible direct flight, but each flight can only be used once per day. Each passenger contributes a demand that they must be routed from a source city to a destination...
CF 1939B - Evidence Board
CF 1939B - Evidence Board Rating: - Tags: *special, constructive algorithms, dfs and similar, graphs, trees Solve time: 51s Verified: no Solution I can’t reliably write a correct editorial for CF 1939B - Evidence Board from what you provided, because the problem statement (inputs/outputs and rules) is missing. Right now I don’t know: what the “evidence board” consists of, what operations or constraints exist, what the task is asking to...
CF 1940C - Burenka and Pether
CF 1940C - Burenka and Pether Rating: - Tags: *special, data structures, dfs and similar, divide and conquer, dsu, graphs, sortings, trees Solve time: 1m 11s Verified: yes Solution Problem Understanding We are given a directed structure over positions 1 to n, where each position carries a value. The key restriction is that movement from one position to another is not arbitrary: you are only allowed to move forward in...
CF 1940A - Parallel Universes
CF 1940A - Parallel Universes Rating: - Tags: *special, constructive algorithms, dfs and similar, dsu, graphs Solve time: 54s Verified: no Solution This prompt is missing the actual problem statement of CF 1940A - Parallel Universes , so a correct editorial cannot be written yet without guessing the task. Right now we only know: problem code: 1940A title: Parallel Universes tags: graphs / DSU / constructive but no input/output definition...
CF 1970G3 - Min-Fund Prison (Hard)
CF 1970G3 - Min-Fund Prison (Hard) Rating: 2400 Tags: bitmasks, dfs and similar, dp, graphs, trees Solve time: 2m 4s Verified: no Solution Problem Understanding We are given an undirected graph representing a prison, where vertices are cells and edges are existing corridors. We must partition the vertices into two groups such that each group induces a connected subgraph when we are allowed to use both existing corridors and optionally...
CF 1970G2 - Min-Fund Prison (Medium)
CF 1970G2 - Min-Fund Prison (Medium) Rating: 2200 Tags: brute force, dfs and similar, dp, graphs, trees Solve time: 2m 12s Verified: no Solution Problem Understanding We are asked to partition a prison into two complexes in a way that minimizes total funding. Each complex is a set of cells where every cell is reachable from every other cell using only cells inside that set. The cost of a complex...
CF 2002D2 - DFS Checker (Hard Version)
CF 2002D2 - DFS Checker (Hard Version) Rating: 2300 Tags: binary search, data structures, dfs and similar, graphs, hashing, trees Solve time: 2m 23s Verified: no Solution Problem Understanding We are given a rooted tree where vertex 1 is the root. Alongside the tree, we maintain a permutation stored in an array indexed by positions, and we repeatedly swap two positions in this array. After each swap, we must decide...
CF 2002D1 - DFS Checker (Easy Version)
CF 2002D1 - DFS Checker (Easy Version) Rating: 1900 Tags: brute force, data structures, dfs and similar, graphs, hashing, trees Solve time: 1m 30s Verified: yes Solution Problem Understanding We are given a perfect binary tree whose vertices are numbered in heap order. Vertex 1 is the root, and for every vertex i > 1 , its parent is i // 2 . A permutation p of all vertices is...
CF 2021E3 - Digital Village (Extreme Version)
CF 2021E3 - Digital Village (Extreme Version) Rating: 2800 Tags: data structures, dfs and similar, dp, dsu, graphs, greedy, math, trees Solve time: 1m 48s Verified: no Solution Problem Understanding We are given a connected village represented as a graph. Each node is a house, and edges are internet cables with a latency weight. Some subset of houses specifically need internet. We are allowed to install servers in up to...
CF 2021E1 - Digital Village (Easy Version)
CF 2021E1 - Digital Village (Easy Version) Rating: 2300 Tags: brute force, data structures, dfs and similar, dp, dsu, fft, graphs, greedy, implementation, math, trees Solve time: 2m 17s Verified: yes Solution Problem Understanding In this problem, we are given a village represented as a connected graph with houses as nodes and internet cables as edges. Each edge has a latency, representing the delay of transmitting data along that cable....
CF 2021E2 - Digital Village (Hard Version)
CF 2021E2 - Digital Village (Hard Version) Rating: 2500 Tags: data structures, dp, dsu, graphs, math, trees Solve time: 1m 56s Verified: no Solution Problem Understanding We are given a connected undirected graph representing a village, where nodes are houses and edges are internet cables with latencies. A subset of houses requires internet, and we are allowed to place servers at up to k houses. Each house needing internet will...
CF 2034C - Trapped in the Witch's Labyrinth
CF 2034C - Trapped in the Witch's Labyrinth Rating: 1400 Tags: constructive algorithms, dfs and similar, graphs, implementation Solve time: 3m 10s Verified: yes Solution Problem Understanding We are given a grid where each cell either forces movement in one of four directions or is still undecided. Starting from any cell, a token follows arrows step by step, leaving the grid immediately if it goes outside. Some cells may form...
CF 2041K - Trophic Balance Species
CF 2041K - Trophic Balance Species Rating: 3100 Tags: binary search, brute force, dfs and similar, graphs Solve time: 1m 4s Verified: yes Solution Problem Understanding We are given an ecosystem modeled as a directed graph, where each node represents a species and each directed edge represents a feeding relationship from prey to predator. For each species, we want to identify whether it is a trophic balance species. A species...
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 2045M - Mirror Maze
CF 2045M - Mirror Maze Rating: 1800 Tags: brute force, dfs and similar, graphs, implementation Solve time: 1m 34s Verified: yes Solution Problem Understanding Think of the laser beam as moving along the grid lines between cells. Whenever the beam enters a cell through one side, the content of that cell determines which side it leaves from. An empty cell does not change direction. A / mirror turns the beam...
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 2052M - Managing Cluster
CF 2052M - Managing Cluster Rating: 2700 Tags: dp, graphs, math, trees Solve time: 2m 6s Verified: no Solution I can't write a correct editorial, proof, algorithm, or solution for Codeforces 2052K from the information provided, because the problem statement, input format, output format, constraints, and samples are all missing. For a 2800-rated problem, the actual statement details are essential. Without them, any discussion of: what the objects represent, what...
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 2052F - Fix Flooded Floor
CF 2052F - Fix Flooded Floor Rating: 1700 Tags: constructive algorithms, dp, graphs Solve time: 1m 46s Verified: yes Solution Problem Understanding We are given a grid with two rows and n columns. Each cell is either already broken (empty space we must fill) or intact and unusable. Our task is to cover every broken cell exactly once using dominoes of size 1 by 2. A domino can be placed...
CF 2052D - DAG Serialization
CF 2052D - DAG Serialization Rating: 2100 Tags: brute force, graphs Solve time: 1m 29s Verified: no Solution Problem Understanding We are given a sequence of operations applied to a single boolean register that starts in the false state. Each operation is either a set or an unset. A set turns the register into true if it was false and returns true in that case, otherwise it leaves it unchanged...
CF 2061H2 - Kevin and Stones (Hard Version)
CF 2061H2 - Kevin and Stones (Hard Version) Rating: 3500 Tags: flows, graphs Solve time: 1m 40s Verified: no Solution Problem Understanding We are given an undirected graph where each vertex may or may not contain a stone. Initially, some vertices are marked with stones, and we are also given a target configuration with the same number of stones. The task is to decide whether we can transform the initial...
CF 2061H1 - Kevin and Stones (Easy Version)
CF 2061H1 - Kevin and Stones (Easy Version) Rating: 3500 Tags: flows, graph matchings, graphs Solve time: 1m 32s Verified: no Solution Problem Understanding Kevin has a graph where each vertex may initially contain a stone or be empty. He also has a target configuration indicating where the stones need to end up. On each move, Kevin can simultaneously move each stone from its current vertex to an adjacent vertex,...
CF 2061G - Kevin and Teams
CF 2061G - Kevin and Teams Rating: 2900 Tags: constructive algorithms, graphs, interactive Solve time: 1m 28s Verified: no Solution Problem Understanding We are given a set of $n$ people where every pair is either connected by a hidden binary relation, friendship or non-friendship. The relation is not known in advance, and in the interactive version it may even react to queries. From these people, we want to pick exactly...
CF 2068K - Amusement Park Rides
CF 2068K - Amusement Park Rides Rating: 3000 Tags: flows, graphs Solve time: 1m 28s Verified: no Solution Problem Understanding We are asked to schedule three friends to ride every attraction in an amusement park exactly once, where each ride has a periodic schedule. Each attraction operates at multiples of its own interval a_i . Every minute, the friends can choose one attraction that is currently available to ride, or...
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 2068A - Condorcet Elections
CF 2068A - Condorcet Elections Rating: 2300 Tags: constructive algorithms, graphs, greedy, probabilities Solve time: 1m 20s Verified: yes Solution Problem Understanding We are given a directed relationship between candidates, where an input pair “a defeats b” is not a vote but a constraint on the final outcome we must simulate. The real output is not a ranking itself but a multiset of full rankings (permutations of all candidates), such...
CF 2080A - Strong Connectivity Strikes Back
CF 2080A - Strong Connectivity Strikes Back Rating: 3200 Tags: *special, constructive algorithms, graphs Solve time: 56s Verified: yes Solution Problem Understanding We are given a directed graph with n vertices and m edges. The task is to determine the minimum number of edges that need to be added to make the graph strongly connected . A graph is strongly connected if there is a directed path from every vertex...
CF 2172N - New Kingdom
CF 2172N - New Kingdom Rating: 2800 Tags: constructive algorithms, graphs, implementation Solve time: 3m 30s Verified: no Solution Problem Understanding We are asked to construct an undirected simple connected graph on $n$ labeled vertices. The graph must satisfy three structural constraints at the same time. First, it must be a single connected component without multi-edges or self-loops. This is just a standard simple connected graph requirement. Second, exactly $k$...
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 2172F - Cluster Computing System
CF 2172F - Cluster Computing System Rating: 1600 Tags: graphs, greedy, math Solve time: 1m 36s Verified: yes Solution Problem Understanding We are given a sequence of $n$ servers, each with a database protocol type $p_i$, which is a positive integer. Initially, the servers are disconnected. We can establish a direct connection between any two servers $u$ and $v$ where $u < v$, and the cost of this connection is...
CF 2181K - Knit the Grid
CF 2181K - Knit the Grid Rating: 3500 Tags: 2-sat, constructive algorithms, graphs, matrices Solve time: 2m 47s Verified: no Solution Problem Understanding The canvas is a rectangular grid of cells, but the real structure lives on its grid graph: vertices are grid intersection points and edges connect adjacent intersections horizontally or vertically. Initially, some collection of simple cycles is drawn along these edges. The cycles are vertex-disjoint, and every...
CF 2181G - Greta's Game
CF 2181G - Greta's Game Rating: 2400 Tags: binary search, dp, graphs, greedy, math Solve time: 2m 9s Verified: no Solution Problem Understanding Each round produces a choice of an integer at every position on a cycle. After the numbers are chosen, we look at each adjacent pair on the cycle and award one point to both endpoints whenever the left endpoint is strictly larger than the right endpoint. Over...
CF 2206G - Extra Transition
CF 2206G - Extra Transition Rating: 3100 Tags: graphs Solve time: 2m 15s Verified: no Solution Problem Understanding We are given a connected undirected graph on $n$ vertices, where vertex $1$ is a start and vertex $n$ is a finish. A “run” is not a general walk but a very specific process: we choose a simple path starting from $1$, never revisiting vertices, and at each step we must move...
CF 2215C - Oriented Journey
CF 2215C - Oriented Journey Rating: 2200 Tags: bitmasks, brute force, communication, constructive algorithms, graphs, interactive, trees Solve time: 1m 54s Verified: no Solution Problem Understanding We are dealing with a two-phase communication system built around a tree. First, an agent receives an undirected tree one edge at a time and must immediately orient each edge. After all edges are oriented, a second agent receives only the resulting directed tree...
CF 2222G - Statistics on Tree
CF 2222G - Statistics on Tree Rating: - Tags: binary search, brute force, dfs and similar, divide and conquer, graphs, trees Solve time: 1m 43s Verified: no Solution Problem Understanding We are working with a tree where each pair of vertices defines a path. For any pair of nodes $(u, v)$, we look at the unique simple path connecting them and then imagine removing all edges on that path from...
CF 2222F - Building Tree
CF 2222F - Building Tree Rating: - Tags: data structures, divide and conquer, dsu, graphs, implementation Solve time: 1m 37s Verified: no Solution Problem Understanding We start with a weighted undirected graph on n vertices. The twist is that distance between two nodes is not the usual shortest path sum. Instead, if you take any path and look at the set of edge weights used on that path, the cost...