Curated sets

Graphs and traversal

BFS, DFS, shortest paths, and trees.

All problems
Total results3,710 problems
TopicsJudge
FenceFrom outside the grid, compute every empty cell's minimum fence breaks with 0-1 BFS, then report the largest value and how many cells attain it.Medium4Shortest pathBFS+2No attempts yet2s64 MBJudgeable
Worst Case ScenarioSimulate staged infection events on a grid where full zones erupt and chain outbreaks to four neighbors until each event settles.Medium4SimulationBFS+1No attempts yet5s128 MBJudgeable
Cash CowSimulate clicks that remove same-color clusters of three or more on a 12 by 10 board with downward and leftward compaction, then count the circles left.Medium4SimulationBFS+1No attempts yet1s128 MBJudgeable
CousinsReconstruct the tree defined by consecutive-number groups and count the cousins of node k.Medium4TreeSimulationNo attempts yet3s128 MBJudgeable
Enterprise EscapeStarting from E, move four-directionally across the grid paying each entered cell's class cost and escape through the cheapest border cell.Medium4Shortest pathMatrix+1No attempts yet10s256 MBJudgeable
DraughtsFind the most dark pieces one light piece can capture in a single chain of diagonal jumps on a 10x10 draughts board.Medium4BacktrackingDFS+1No attempts yet2s128 MBJudgeable
Lock Patterns and Spanning TreesCount the spanning trees of an m by m king-move grid for m up to 6 by evaluating a cofactor of its Laplacian matrix.Medium4MatrixMath+2No attempts yet1s128 MBJudgeable
Metro Manila DetourCompute the shortest driving distance between two intersections on concentric ring roads and radial roads with one ring and one spoke closed.Medium4Shortest pathGraphNo attempts yet5s128 MBJudgeable
More Fun in BicolGiven unit compass offsets between named places, answer each query with the direction from one place to the other or report it as unknown.Medium4Union-findGraphNo attempts yet5s128 MBJudgeable
Tree ColoringCount colorings of an N-node tree with K colors so adjacent nodes differ, modulo 93563.Medium4Dynamic programmingTree+1No attempts yet1s128 MBJudgeable
Vacuum WorldTwo cleaners with different power and move costs roam a row of rooms and suck dirt, and the goal is the cheapest move-and-suck sequence that cleans every room.Medium4Shortest pathBrute force+1No attempts yet5s128 MBJudgeable
Pancake sortingSort a stack of up to 8 pancakes into descending order with the fewest suffix flips.Medium4BFSBrute forceNo attempts yet2s512 MBJudgeable
Triball RankingOrder all k players to satisfy every match result and return the lexicographically smallest lineup, or 0 when no lineup fits.Medium4Topological sortGraph+1No attempts yet2s512 MBJudgeable
Vacation PlanningFor each query, find the cheapest directed flight route from start to end that visits at least one hub, then report the count and total cost.Medium4Shortest pathGraphNo attempts yet1s128 MBJudgeable
ClawsCompute each hinge grade from subtree and root-path bar weights and report the largest root-to-claw sum of grades over all claws.Medium4TreeDFSNo attempts yet2s512 MBJudgeable
PathsFind the cheapest total cost among the directed paths from node 0 to node 1 that use the fewest links.Medium4BFSDynamic programmingNo attempts yet2s512 MBJudgeable
RankCount the players that lie on a directed win cycle built from the game results.Medium4GraphDFSNo attempts yet2s1024 MBJudgeable
SpectrumMaintain an undirected graph of named targets and answer per-query BFS hop histograms and pairwise hop distances.Medium4BFSGraph+1No attempts yet3s128 MBJudgeable
Door ManYou decide whether one walk from the start room closes every open door exactly once and ends in room 0.Medium4GraphDFSNo attempts yet1s128 MBJudgeable
Watering the FieldsConnect all fields with pipes costing at least C while minimizing total squared distance, or report -1 when impossible.Medium4Minimum spanning treeUnion-find+1No attempts yet1s128 MBJudgeable
Decorating the PasturesColor each connected group of pastures with two letters so neighbors differ and the count of J signs is as large as possible.Medium4BFSGraphNo attempts yet1s128 MBJudgeable
TourismVisit the given sights in order on a grid with extra northeast diagonals and minimize the total number of road segments traveled.Medium4Shortest pathMathNo attempts yet1s128 MBJudgeable
GatesFind the minimum travel time for each query pair of gates using walking and directed walkways.Medium4Shortest pathGraphNo attempts yet2s256 MBJudgeable
Maximum Jumps for a Checkers KingGiven up to 20 checkerboards, find for each board the red king with the longest capture chain and print its row, column, and jump count.Medium4BacktrackingDFS+1No attempts yet1s256 MBJudgeable
The Minions Build a Brick WallCover a grid with obstacles using dominoes to leave as few open cells bare as possible.Medium4GraphBFS+1No attempts yet1s256 MBJudgeable
Traffic CongestionPick the tree city that minimizes the largest number of fans traveling on any single road when all fans leave the arena city.Medium4TreeDFSNo attempts yet3s256 MBJudgeable
HackingStarting from the hacked computer, count reachable computers through dependency edges and report the longest infection time.Medium4Shortest pathGraph+1No attempts yet2s256 MBJudgeable
Man in the MiddleDecide whether removing some single person disconnects the connected friendship network.Medium4DFSGraphNo attempts yet3s256 MBJudgeable
HikingFind the cheapest 8-direction path from the start to the highest cell of a height grid where flat steps cost 1 and a height change of d costs (d+1) squared.Medium4Shortest pathGraph+1No attempts yet3s256 MBJudgeable
Turtle ElderPick safe start and end islands in a tree so the sum of values along the path is as large as possible, staying home when the best sum is not positive.Medium4TreeDynamic programmingNo attempts yet5s256 MBJudgeable
Two's Round TripsList every route that starts at house 2, visits no house twice, returns to house 2, and print them as digit strings in numeric order.Medium4BacktrackingDFS+1No attempts yet1s256 MBJudgeable
Button BashingPress add and subtract buttons from 0, clamped between 0 and 3600, to reach a target time in the fewest presses or the nearest reachable longer time.Medium4BFSShortest path+1No attempts yet1s256 MBJudgeable
The Maze MakersValidate hex-encoded grid mazes by checking that the two openings connect, every cell is reachable, and no cycles create multiple paths.Medium4GraphDFSNo attempts yet1s256 MBJudgeable
The Mountain of Gold?Decide whether portal hops from mountain 0 can return to mountain 0 at a strictly earlier time.Medium4Shortest pathGraphNo attempts yet1s256 MBJudgeable
Switch toggling instructionSimulate trains arriving over time through a binary switch tree and emit the fewest latest possible toggles routing each train to its platform.Medium4SimulationTreeNo attempts yet2s256 MBJudgeable
QuentoFind a no-revisit path using exactly M digits on the fixed 3x3 board whose left-to-right value equals N and print the lexicographically smallest one.Medium4BacktrackingDFSNo attempts yet1s256 MBJudgeable
Exploration TeamFind the size of the largest group where every member has at least k friends inside the group.Medium4GraphQueueNo attempts yet1s256 MBJudgeable
Human CannonballFind the fastest route from start to target by running at 5 m/s and chaining optional 50-meter cannon shots that cost 2 seconds each.Medium4Shortest pathGraphNo attempts yet1s256 MBJudgeable
UnitsGiven N-1 pairwise conversion relations, sort the units from largest to smallest and print the chain with the largest unit set to 1.Medium4GraphSorting+1No attempts yet3s256 MBJudgeable
Trapezoid WalkwayFind the cheapest chain of trapezoid stones joining two given widths, where each stone links its two edge lengths at a cost tied to its area.Medium4Shortest pathGraphNo attempts yet2s256 MBJudgeable
Flowery TrailsAdd twice the length of every trail that lies on some shortest route from point 0 to point P-1.Medium4Shortest pathGraphNo attempts yet2s256 MBJudgeable
Book ClubDecide whether each of N members can receive a distinct liked book, given M like declarations.Medium4GraphBFS+1No attempts yet2s256 MBJudgeable
WormholesGiven planet coordinates and directed zero-cost wormholes, report the shortest travel distance for each queried planet pair.Medium4Shortest pathGraph+1No attempts yet5s256 MBJudgeable
ElevatorsFind the shortest total ride distance from the start floor to the target floor by switching between elevators that each serve only certain floors.Medium4Shortest pathGraphNo attempts yet2s256 MBJudgeable
NIKODecide for each listed O-V-N lineup whether 10 of the M candidates can cover its lines using only positions each player accepts.Medium4GraphNo attempts yet1s256 MBJudgeable
Binary Mobile WidthCompute the horizontal width of a balanced binary mobile from rod lengths and bead weights using torque balance.Medium4TreeDFSNo attempts yet1s256 MBJudgeable
Pangaea 1After each added road, compute the cheapest total length connecting all cities and XOR the m totals per test case.Medium4Minimum spanning treeUnion-find+1No attempts yet20s256 MBJudgeable
AirportEach arriving plane takes the largest free gate up to its limit gi, and the count stops at the first plane with no free gate.Medium4Union-findGreedyNo attempts yet1s256 MBJudgeable
NetworkAdd the fewest edges to a tree so it stays connected after any single edge breaks, pairing leaves in the prescribed DFS order.Medium4TreeDFS+1No attempts yet1s256 MBJudgeable
The Knight's Scouting MissionFind the shortest knight distance from (1,1) to (r,c) on an r by c board, count those routes modulo 1000000009, and report None when unreachable.Medium4BFSDynamic programmingNo attempts yet2s256 MBJudgeable
Troop MovementFind the route between two cities whose narrowest road is as wide as possible and report that width.Medium4Minimum spanning treeUnion-find+1No attempts yet2s256 MBJudgeable
Torn to PiecesRebuild the subway graph from the torn map pieces and print the stations on the path from the start to the destination, or no route found.Medium4GraphBFSNo attempts yet2s256 MBJudgeable
City PlanningRebuild the smallest one-way road network matching a given reachability matrix, with cycles inside mutually reachable groups and cover edges between groups.Medium4GraphMatrix+1No attempts yet2s256 MBJudgeable
NurikabeCheck whether each numbered island has the required size, all water cells connect, and no 2 by 2 block is all water.Medium4BFSMatrix+1No attempts yet1s256 MBJudgeable
Travelling TomFind the cheapest route that starts at the first listed city, visits every city in the given order using any connecting flights, then returns to the start.Medium4Shortest pathGraphNo attempts yet1s256 MBJudgeable
C.S.I.: P15Count ground-connected 8-connected flower components and isolated /\/\ bird patterns in each ASCII picture.Medium4DFSString matchingNo attempts yet1s256 MBJudgeable
Coast LengthCount the total length of borders between land and sea connected to the outside of the grid, excluding enclosed lakes.Medium4BFSGraph+1No attempts yet1s256 MBJudgeable
The Party That Never EndsFor each query, decide whether the shortest travel time from hall A to hall B fits within C using all-pairs shortest paths.Medium4Shortest pathGraphNo attempts yet2s256 MBJudgeable
Articulation pointsFind and list in increasing order every vertex whose removal increases the number of connected components in an undirected graph.Medium4DFSGraphNo attempts yet1s256 MBJudgeable
SV FiltersCompute the max flow between nodes 0 and 1, then remove the size-P edges reachable from node 0 and compute the max flow again.Medium4GraphBFS+1No attempts yet1s256 MBJudgeable
One Stroke DrawingDecide whether given line segments form a shape drawable in one stroke without retracing any segment.Medium4GraphUnion-findNo attempts yet2s256 MBJudgeable
Job AssignmentAssign each of N employees at most one job they can do so the number of finished jobs is as large as possible.Medium4GraphDFSNo attempts yet2s256 MBJudgeable
Job Assignment 2Assign each of M jobs to one of N employees who can do it with at most two jobs per employee to handle as many jobs as possible.Medium4GraphBFS+1No attempts yet4s256 MBJudgeable
Job Assignment 3Each worker takes jobs only from a given eligible list, with K workers allowed two jobs, to finish as many of M jobs as possible.Medium4GraphNo attempts yet3s256 MBJudgeable
Graph bridgesFind every bridge in a connected undirected graph and print them sorted by endpoint.Medium4DFSGraphNo attempts yet1s256 MBJudgeable
FloydFor every pair of n cities, compute the cheapest directed bus fare from up to 100,000 routes and print 0 where no route connects them.Medium4Shortest pathGraph+1No attempts yet1s256 MBJudgeable
Buying Books 2Find the maximum number of book copies N buyers can purchase from M stores under per-pair purchase limits.Medium4GraphNo attempts yet1s256 MBJudgeable
Dr Who's BanquetBuild a chat graph whose vertex degrees equal the given wishes with the stated greedy construction, or print fail.Medium4GraphGreedy+1No attempts yet1s256 MBJudgeable
Candy BombersAssign each pilot to at most one plane they can fly to maximize the number of planes sent.Medium4GraphDFSNo attempts yet1s256 MBJudgeable
Lowest Common AncestorGiven a rooted tree, answer each query with the number of the deepest vertex that is an ancestor of both given vertices.Medium4TreeDFSNo attempts yet3s256 MBJudgeable
Lowest Common Ancestor 2Given a rooted tree with up to 100,000 nodes, answer up to 100,000 lowest common ancestor queries.Medium4TreeDFSNo attempts yet1.5s256 MBJudgeable
GaCount the empty squares White can reach by expanding from its stones through empty squares without crossing Black stones.Medium4BFSGraph+1No attempts yet1s256 MBJudgeable
Puyo PuyoCount how many chain reactions occur when groups of four or more same-color puyos pop and gravity settles the 12 by 6 field.Medium4BFSSimulationNo attempts yet1s256 MBJudgeable
Baegyang Road BreakGiven a graph with one-way and two-way roads, answer many queries for the minimum number of one-way roads to reverse to reach each destination.Medium4Shortest pathGraphNo attempts yet1s256 MBJudgeable
Grid JumpsFind the fewest digit-length jumps from the top-left cell to the bottom-right cell of a grid, or print IMPOSSIBLE.Medium4BFSGraphNo attempts yet2s256 MBJudgeable
Six DegreesCount the devices that cannot reach every other device within 6 hops and answer YES when they are at most 5 percent of the network.Medium4BFSGraphNo attempts yet2s256 MBJudgeable
Time MachineCompute the fastest times from city 1 over bus routes with possibly negative durations, or print -1 when a reachable negative cycle exists.Medium4Shortest pathGraphNo attempts yet1s256 MBJudgeable
RingsLabel each tree square with its edge-step distance to the nearest empty square or the outside of the grid and print the dot-padded grid.Medium4BFSMatrix+1No attempts yet1s256 MBJudgeable
Milk PailsFill, empty, and pour two pails of sizes X and Y within K moves to get a combined amount as close to M as possible.Medium4BFSSimulationNo attempts yet2s512 MBJudgeable
Dynamic Grid (Large)Point updates flip binary grid cells and each query asks for the number of edge-connected groups of 1s.Medium4BFSMatrix+1No attempts yet5s512 MBJudgeable
gCampus (Small)For each road, decide whether it lies on a shortest path between some pair of offices and list the ones that never do.Medium4Shortest pathGraphNo attempts yet5s512 MBJudgeable
Cube IV (Small)Given a square grid holding 1 to S squared, find the smallest start of the longest chain that steps to an orthogonal neighbor one higher and report its length.Medium4DFSDynamic programming+1No attempts yet5s512 MBJudgeable
Minesweeper Minimum ClicksCount the minimum clicks to reveal all safe cells, where each zero region opens with one click and each leftover numbered cell needs its own.Medium4BFSGraph+1No attempts yet5s512 MBJudgeable
Minimum Clicks in MinesweeperFind the fewest clicks that reveal every safe cell, since one click opens each zero region and each remaining safe cell costs one click.Medium4DFSGraph+1No attempts yet5s512 MBJudgeable
Taking Metro (Small)Find the fastest route between two metro stations, combining per-line boarding waits, ride times, and tunnel walks.Medium4Shortest pathGraphNo attempts yet5s512 MBJudgeable
EnclosurePlace the fewest stones on an N by M grid of at most 20 cells so at least K points are cut off from the border.Medium4Brute forceBFS+1No attempts yet5s512 MBJudgeable
Rational Number Tree (Small)Given the level-order listing of the rational number tree, find the n-th fraction and the position of a given fraction.Medium4TreeBFS+1No attempts yet5s512 MBJudgeable
Twirling Towards Freedom (Small)Each minute you may stay put or rotate 90 degrees clockwise around one of the stars to maximize the distance from the origin after M minutes.Medium4Brute forceGeometry+1No attempts yet5s512 MBJudgeable
Shifting Paths (Large)Count how many paths the alternating left-right walk takes from clearing 1 to clearing N, or report Infinity if it never arrives.Medium4SimulationGraphNo attempts yet30s512 MBJudgeable
Diamond Inheritance (Small)Decide whether any pair of classes in each inheritance diagram has two distinct inheritance paths between them.Medium4GraphDFSNo attempts yet5s512 MBJudgeable
Meeting Point (Small)Friends with different speeds start from given cities and must meet in one city, so minimize the worst arrival time over all cities.Medium4Shortest pathGraphNo attempts yet5s512 MBJudgeable
Number Sets (Small)Count how many disjoint sets remain after merging numbers in [A, B] that share a prime factor of at least P.Medium4Union-findNumber theoryNo attempts yet5s512 MBJudgeable
Twibet (Large)In a graph where each monk follows exactly one other, count for every starter how many monks hear the whisper passed down through followers.Medium4GraphDFSNo attempts yet5s512 MBJudgeable
Grid EscapePoint each grid room at one door so exactly K players walk out of the grid, and print the direction grid or IMPOSSIBLE.Medium4GraphSimulation+1No attempts yet20s1024 MBJudgeable
Wi-Fi Towers (Small)Choose which towers to upgrade to protocol B so the total score is maximized, where upgrading a tower forces every tower in its range to be upgraded too.Medium4GraphBrute force+1No attempts yet5s512 MBJudgeable
Decision TreeParse a recursively defined decision tree, then for each animal walk the tree using its features and multiply node weights to get the probability.Medium4TreeRecursion+2No attempts yet5s512 MBJudgeable
Watersheds (Small)Given a height grid, follow each cell's outflow to its sink and label cells by shared sink, choosing basin letters to make the row-wise string smallest.Medium4GraphDFS+2No attempts yet5s512 MBJudgeable
Ceiling FunctionInsert each prototype's values into a binary search tree in order, then count how many distinct tree shapes appear across the prototypes.Medium4TreeImplementation+1No attempts yet5s512 MBJudgeable
Weekly MeetingFor each member's house, add the shortest distances to two fixed nodes and sum all results, counting unreachable as -1.Medium4Shortest pathGraph+1No attempts yet1s512 MBJudgeable
Road Network of a Perfect Binary TreeFind the minimum number of cars whose vertex-disjoint paths cover every vertex of a perfect binary tree of height H exactly once.Medium4TreeDynamic programming+1No attempts yet2s512 MBJudgeable