Curated sets
Graphs and traversal
BFS, DFS, shortest paths, and trees.
Total results3,710 problems
| Topics | Judge | |||||
|---|---|---|---|---|---|---|
| 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. | Medium4 | Shortest pathBFS+2 | No attempts yet | 2s | 64 MB | Judgeable |
| Worst Case ScenarioSimulate staged infection events on a grid where full zones erupt and chain outbreaks to four neighbors until each event settles. | Medium4 | SimulationBFS+1 | No attempts yet | 5s | 128 MB | Judgeable |
| 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. | Medium4 | SimulationBFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| CousinsReconstruct the tree defined by consecutive-number groups and count the cousins of node k. | Medium4 | TreeSimulation | No attempts yet | 3s | 128 MB | Judgeable |
| Enterprise EscapeStarting from E, move four-directionally across the grid paying each entered cell's class cost and escape through the cheapest border cell. | Medium4 | Shortest pathMatrix+1 | No attempts yet | 10s | 256 MB | Judgeable |
| DraughtsFind the most dark pieces one light piece can capture in a single chain of diagonal jumps on a 10x10 draughts board. | Medium4 | BacktrackingDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium4 | MatrixMath+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Metro Manila DetourCompute the shortest driving distance between two intersections on concentric ring roads and radial roads with one ring and one spoke closed. | Medium4 | Shortest pathGraph | No attempts yet | 5s | 128 MB | Judgeable |
| 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. | Medium4 | Union-findGraph | No attempts yet | 5s | 128 MB | Judgeable |
| Tree ColoringCount colorings of an N-node tree with K colors so adjacent nodes differ, modulo 93563. | Medium4 | Dynamic programmingTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | Shortest pathBrute force+1 | No attempts yet | 5s | 128 MB | Judgeable |
| Pancake sortingSort a stack of up to 8 pancakes into descending order with the fewest suffix flips. | Medium4 | BFSBrute force | No attempts yet | 2s | 512 MB | Judgeable |
| Triball RankingOrder all k players to satisfy every match result and return the lexicographically smallest lineup, or 0 when no lineup fits. | Medium4 | Topological sortGraph+1 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph | No attempts yet | 1s | 128 MB | Judgeable |
| ClawsCompute each hinge grade from subtree and root-path bar weights and report the largest root-to-claw sum of grades over all claws. | Medium4 | TreeDFS | No attempts yet | 2s | 512 MB | Judgeable |
| PathsFind the cheapest total cost among the directed paths from node 0 to node 1 that use the fewest links. | Medium4 | BFSDynamic programming | No attempts yet | 2s | 512 MB | Judgeable |
| RankCount the players that lie on a directed win cycle built from the game results. | Medium4 | GraphDFS | No attempts yet | 2s | 1024 MB | Judgeable |
| SpectrumMaintain an undirected graph of named targets and answer per-query BFS hop histograms and pairwise hop distances. | Medium4 | BFSGraph+1 | No attempts yet | 3s | 128 MB | Judgeable |
| Door ManYou decide whether one walk from the start room closes every open door exactly once and ends in room 0. | Medium4 | GraphDFS | No attempts yet | 1s | 128 MB | Judgeable |
| Watering the FieldsConnect all fields with pipes costing at least C while minimizing total squared distance, or report -1 when impossible. | Medium4 | Minimum spanning treeUnion-find+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | BFSGraph | No attempts yet | 1s | 128 MB | Judgeable |
| TourismVisit the given sights in order on a grid with extra northeast diagonals and minimize the total number of road segments traveled. | Medium4 | Shortest pathMath | No attempts yet | 1s | 128 MB | Judgeable |
| GatesFind the minimum travel time for each query pair of gates using walking and directed walkways. | Medium4 | Shortest pathGraph | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium4 | BacktrackingDFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| The Minions Build a Brick WallCover a grid with obstacles using dominoes to leave as few open cells bare as possible. | Medium4 | GraphBFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Traffic CongestionPick the tree city that minimizes the largest number of fans traveling on any single road when all fans leave the arena city. | Medium4 | TreeDFS | No attempts yet | 3s | 256 MB | Judgeable |
| HackingStarting from the hacked computer, count reachable computers through dependency edges and report the longest infection time. | Medium4 | Shortest pathGraph+1 | No attempts yet | 2s | 256 MB | Judgeable |
| Man in the MiddleDecide whether removing some single person disconnects the connected friendship network. | Medium4 | DFSGraph | No attempts yet | 3s | 256 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph+1 | No attempts yet | 3s | 256 MB | Judgeable |
| 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. | Medium4 | TreeDynamic programming | No attempts yet | 5s | 256 MB | Judgeable |
| 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. | Medium4 | BacktrackingDFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | BFSShortest path+1 | No attempts yet | 1s | 256 MB | Judgeable |
| The Maze MakersValidate hex-encoded grid mazes by checking that the two openings connect, every cell is reachable, and no cycles create multiple paths. | Medium4 | GraphDFS | No attempts yet | 1s | 256 MB | Judgeable |
| The Mountain of Gold?Decide whether portal hops from mountain 0 can return to mountain 0 at a strictly earlier time. | Medium4 | Shortest pathGraph | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | SimulationTree | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium4 | BacktrackingDFS | No attempts yet | 1s | 256 MB | Judgeable |
| Exploration TeamFind the size of the largest group where every member has at least k friends inside the group. | Medium4 | GraphQueue | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph | No attempts yet | 1s | 256 MB | Judgeable |
| UnitsGiven N-1 pairwise conversion relations, sort the units from largest to smallest and print the chain with the largest unit set to 1. | Medium4 | GraphSorting+1 | No attempts yet | 3s | 256 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph | No attempts yet | 2s | 256 MB | Judgeable |
| Flowery TrailsAdd twice the length of every trail that lies on some shortest route from point 0 to point P-1. | Medium4 | Shortest pathGraph | No attempts yet | 2s | 256 MB | Judgeable |
| Book ClubDecide whether each of N members can receive a distinct liked book, given M like declarations. | Medium4 | GraphBFS+1 | No attempts yet | 2s | 256 MB | Judgeable |
| WormholesGiven planet coordinates and directed zero-cost wormholes, report the shortest travel distance for each queried planet pair. | Medium4 | Shortest pathGraph+1 | No attempts yet | 5s | 256 MB | Judgeable |
| ElevatorsFind the shortest total ride distance from the start floor to the target floor by switching between elevators that each serve only certain floors. | Medium4 | Shortest pathGraph | No attempts yet | 2s | 256 MB | Judgeable |
| NIKODecide for each listed O-V-N lineup whether 10 of the M candidates can cover its lines using only positions each player accepts. | Medium4 | Graph | No attempts yet | 1s | 256 MB | Judgeable |
| Binary Mobile WidthCompute the horizontal width of a balanced binary mobile from rod lengths and bead weights using torque balance. | Medium4 | TreeDFS | No attempts yet | 1s | 256 MB | Judgeable |
| Pangaea 1After each added road, compute the cheapest total length connecting all cities and XOR the m totals per test case. | Medium4 | Minimum spanning treeUnion-find+1 | No attempts yet | 20s | 256 MB | Judgeable |
| 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. | Medium4 | Union-findGreedy | No attempts yet | 1s | 256 MB | Judgeable |
| NetworkAdd the fewest edges to a tree so it stays connected after any single edge breaks, pairing leaves in the prescribed DFS order. | Medium4 | TreeDFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | BFSDynamic programming | No attempts yet | 2s | 256 MB | Judgeable |
| Troop MovementFind the route between two cities whose narrowest road is as wide as possible and report that width. | Medium4 | Minimum spanning treeUnion-find+1 | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium4 | GraphBFS | No attempts yet | 2s | 256 MB | Judgeable |
| City PlanningRebuild the smallest one-way road network matching a given reachability matrix, with cycles inside mutually reachable groups and cover edges between groups. | Medium4 | GraphMatrix+1 | No attempts yet | 2s | 256 MB | Judgeable |
| NurikabeCheck whether each numbered island has the required size, all water cells connect, and no 2 by 2 block is all water. | Medium4 | BFSMatrix+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph | No attempts yet | 1s | 256 MB | Judgeable |
| C.S.I.: P15Count ground-connected 8-connected flower components and isolated /\/\ bird patterns in each ASCII picture. | Medium4 | DFSString matching | No attempts yet | 1s | 256 MB | Judgeable |
| Coast LengthCount the total length of borders between land and sea connected to the outside of the grid, excluding enclosed lakes. | Medium4 | BFSGraph+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph | No attempts yet | 2s | 256 MB | Judgeable |
| Articulation pointsFind and list in increasing order every vertex whose removal increases the number of connected components in an undirected graph. | Medium4 | DFSGraph | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | GraphBFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| One Stroke DrawingDecide whether given line segments form a shape drawable in one stroke without retracing any segment. | Medium4 | GraphUnion-find | No attempts yet | 2s | 256 MB | Judgeable |
| Job AssignmentAssign each of N employees at most one job they can do so the number of finished jobs is as large as possible. | Medium4 | GraphDFS | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium4 | GraphBFS+1 | No attempts yet | 4s | 256 MB | Judgeable |
| 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. | Medium4 | Graph | No attempts yet | 3s | 256 MB | Judgeable |
| Graph bridgesFind every bridge in a connected undirected graph and print them sorted by endpoint. | Medium4 | DFSGraph | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Buying Books 2Find the maximum number of book copies N buyers can purchase from M stores under per-pair purchase limits. | Medium4 | Graph | No attempts yet | 1s | 256 MB | Judgeable |
| Dr Who's BanquetBuild a chat graph whose vertex degrees equal the given wishes with the stated greedy construction, or print fail. | Medium4 | GraphGreedy+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Candy BombersAssign each pilot to at most one plane they can fly to maximize the number of planes sent. | Medium4 | GraphDFS | No attempts yet | 1s | 256 MB | Judgeable |
| Lowest Common AncestorGiven a rooted tree, answer each query with the number of the deepest vertex that is an ancestor of both given vertices. | Medium4 | TreeDFS | No attempts yet | 3s | 256 MB | Judgeable |
| Lowest Common Ancestor 2Given a rooted tree with up to 100,000 nodes, answer up to 100,000 lowest common ancestor queries. | Medium4 | TreeDFS | No attempts yet | 1.5s | 256 MB | Judgeable |
| GaCount the empty squares White can reach by expanding from its stones through empty squares without crossing Black stones. | Medium4 | BFSGraph+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | BFSSimulation | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph | No attempts yet | 1s | 256 MB | Judgeable |
| Grid JumpsFind the fewest digit-length jumps from the top-left cell to the bottom-right cell of a grid, or print IMPOSSIBLE. | Medium4 | BFSGraph | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium4 | BFSGraph | No attempts yet | 2s | 256 MB | Judgeable |
| Time MachineCompute the fastest times from city 1 over bus routes with possibly negative durations, or print -1 when a reachable negative cycle exists. | Medium4 | Shortest pathGraph | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | BFSMatrix+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | BFSSimulation | No attempts yet | 2s | 512 MB | Judgeable |
| Dynamic Grid (Large)Point updates flip binary grid cells and each query asks for the number of edge-connected groups of 1s. | Medium4 | BFSMatrix+1 | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | DFSDynamic programming+1 | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | BFSGraph+1 | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | DFSGraph+1 | No attempts yet | 5s | 512 MB | Judgeable |
| Taking Metro (Small)Find the fastest route between two metro stations, combining per-line boarding waits, ride times, and tunnel walks. | Medium4 | Shortest pathGraph | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | Brute forceBFS+1 | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | TreeBFS+1 | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | Brute forceGeometry+1 | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | SimulationGraph | No attempts yet | 30s | 512 MB | Judgeable |
| Diamond Inheritance (Small)Decide whether any pair of classes in each inheritance diagram has two distinct inheritance paths between them. | Medium4 | GraphDFS | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | Shortest pathGraph | No attempts yet | 5s | 512 MB | Judgeable |
| Number Sets (Small)Count how many disjoint sets remain after merging numbers in [A, B] that share a prime factor of at least P. | Medium4 | Union-findNumber theory | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | GraphDFS | No attempts yet | 5s | 512 MB | Judgeable |
| Grid EscapePoint each grid room at one door so exactly K players walk out of the grid, and print the direction grid or IMPOSSIBLE. | Medium4 | GraphSimulation+1 | No attempts yet | 20s | 1024 MB | Judgeable |
| 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. | Medium4 | GraphBrute force+1 | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | TreeRecursion+2 | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | GraphDFS+2 | No attempts yet | 5s | 512 MB | Judgeable |
| Ceiling FunctionInsert each prototype's values into a binary search tree in order, then count how many distinct tree shapes appear across the prototypes. | Medium4 | TreeImplementation+1 | No attempts yet | 5s | 512 MB | Judgeable |
| Weekly MeetingFor each member's house, add the shortest distances to two fixed nodes and sum all results, counting unreachable as -1. | Medium4 | Shortest pathGraph+1 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium4 | TreeDynamic programming+1 | No attempts yet | 2s | 512 MB | Judgeable |