Curated sets
Graphs and traversal
BFS, DFS, shortest paths, and trees.
Total results3,710 problems
| Topics | Judge | |||||
|---|---|---|---|---|---|---|
| A graph that times out coloring backtrackingPrint one fixed graph: a 55-vertex clique joined by a path, chosen to make a backtracking coloring solver time out. | Easy1 | GraphImplementation+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Friend countsCount the friends of each of N students from M mutual friendship pairs and print the N totals in order. | Easy1 | GraphImplementation | No attempts yet | 1s | 256 MB | Judgeable |
| Hands are faster than computersPrint a fixed 4-vertex, 5-edge graph and a fixed proper 4-coloring, with no input to read. | Easy1 | ImplementationGraph | No attempts yet | 2s | 512 MB | Judgeable |
| Is Dinic quartic?Print a fixed 4-vertex, 5-edge flow network with the exact edges and capacities given in the statement. | Easy1 | GraphImplementation+1 | No attempts yet | 2s | 512 MB | Judgeable |
| VirusCount how many computers other than computer 1 lie in computer 1's connected component of a small undirected graph. | Easy2 | GraphBFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| K-Graph OddityCompute the maximum vertex degree in a graph and output the smallest odd integer greater than or equal to it. | Easy2 | GraphImplementation+1 | No attempts yet | 1s | 128 MB | Judgeable |
| UnfriendCount the subsets of nodes in a rooted tree that can be removed, where removing a node forces removal of all its descendants. | Easy2 | TreeBrute force+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Making test data 8Print a specific fixed graph: 98 vertices, 1501 edges forming a complete bipartite graph, using the exact listed edge order. | Easy2 | GraphImplementation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Huffman TreeGiven Z characters and arity N, decode the stored digit string into the per-character encoding. | Easy2 | TreeString+1 | No attempts yet | 3s | 128 MB | Judgeable |
| The Friend of My Enemy Is My EnemyPrint the direct friends of suspect s in increasing order for each network. | Easy2 | GraphSorting | No attempts yet | 1s | 128 MB | Judgeable |
| Sanggeun's travelsGiven a connected graph of N countries and M flights, find the fewest flights that visit every country. | Easy2 | Graph | No attempts yet | 1s | 256 MB | Judgeable |
| Toroidal gridPrint the given snake sweep of columns 0 to n-2 plus the climb up column n-1 to list a Hamiltonian cycle of the m by n toroidal grid. | Easy2 | ImplementationGraph | No attempts yet | 1s | 256 MB | Judgeable |
| Counting FriendsCount the friends of each of N students from M mutual friendship pairs and print the N totals. | Easy2 | GraphArray | No attempts yet | 1s | 256 MB | Judgeable |
| ICPC CalculatorEvaluate a dot-indented prefix expression where + sums its operands and * multiplies them. | Easy2 | RecursionTree+1 | No attempts yet | 1s | 256 MB | Judgeable |
| ITAI VirusCount the initially infected cities plus every city directly joined to one by a single road. | Easy2 | GraphImplementation | No attempts yet | 1s | 256 MB | Judgeable |
| Graph Maximum MatchingGiven a small graph, decide whether some edges can be kept so every vertex has degree exactly 1. | Easy2 | GraphBacktracking+1 | No attempts yet | 2s | 512 MB | Judgeable |
| László BabaiFor each of up to 100 test cases, decide whether two simple graphs on 3 vertices given by their edge lists are isomorphic. | Easy2 | GraphBrute force+1 | No attempts yet | 1s | 256 MB | Judgeable |
| LiesUsing union-find on party attendees, determine which parties can be exaggerated without conflicting with people who must always hear the truth. | Easy3 | Union-findGraph+1 | No attempts yet | 2s | 128 MB | Judgeable |
| FriendsGiven an N x N friendship matrix (N ≤ 50), find the maximum count of people reachable within two friendship links from any single person. | Easy3 | GraphMatrix+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Leaf Nodes in a TreeGiven a tree by parent array, delete a node and all its descendants, then count how many leaf nodes remain. | Easy3 | TreeDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Come Back HomeCount simple paths of exact length K from the bottom-left to the top-right cell of a small grid, avoiding blocked cells and revisits. | Easy3 | BacktrackingDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| DFS and BFSGiven an undirected graph, output the vertex visit order for DFS then BFS starting from a given vertex, always preferring the smallest-numbered neighbor. | Easy3 | DFSBFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Six Degrees of Kevin BaconGiven an unweighted friendship graph, find the vertex whose sum of shortest distances to all others is minimal, breaking ties by smallest index. | Easy3 | BFSGraph+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Hide and SeekCompute the minimum number of moves to reach position K from N on the number line using BFS with steps +1, -1, or doubling. | Easy3 | BFSGraph | No attempts yet | 2s | 128 MB | Judgeable |
| Disjoint Set OperationsImplement a union-find structure that merges sets and answers whether two elements share a set across a sequence of operations. | Easy3 | Union-find | No attempts yet | 2s | 128 MB | Judgeable |
| Avoiding Food WasteGiven a grid marked with food waste cells, find the size of the largest 4-directionally connected component using BFS/DFS or union-find. | Easy3 | BFSDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Painted AreasCount connected components of 1-cells in a grid (4-directional adjacency) and output the count and the size of the largest component. | Easy3 | BFSDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Travel PlanGiven an adjacency matrix of cities, decide if consecutive cities in a given visit order all lie in the same connected component. | Easy3 | Union-findGraph+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Tree TraversalBuild a binary tree from parent-child input and print its preorder, inorder, and postorder traversals. | Easy3 | TreeDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Maze SearchFind the minimum number of cells traversed on a grid path from top-left to bottom-right using BFS shortest path. | Easy3 | BFSGraph+1 | No attempts yet | 1s | 192 MB | Judgeable |
| Kinship DistanceGiven a family forest of parent-child edges, find the shortest kinship distance between two given people or output -1 if unconnected. | Easy3 | GraphBFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Chairperson CandidatesGiven a friendship graph, compute each member's eccentricity via shortest paths and report the minimum eccentricity value with all members achieving it. | Easy3 | GraphBFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Housing Complex NumberingGiven a binary grid, count connected groups of adjacent 1-cells and print the number of groups plus each group's size in ascending order. | Easy3 | BFSGraph+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Keypad PasswordsCount length-N digit sequences on a phone keypad where consecutive digits must be adjacent keys, modulo 1,234,567, for up to N=1000. | Easy3 | Dynamic programmingGraph+1 | No attempts yet | 1s | 128 MB | Judgeable |
| RadioGiven a start and target frequency plus up to 5 preset shortcut buttons, find the minimum presses using +1, -1, or jump to a preset to reach the target. | Easy3 | GraphShortest path+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Unreachable FunctionsGiven a control flow graph built from three instruction types with fall-through or jump edges, count how many functions are unreachable from the first one. | Easy3 | GraphBFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| GatesGiven an acyclic NAND-gate circuit whose inputs are all tied to one variable x, decide whether the overall output depends on x (answer 1) or is constant (answer 0). | Easy3 | SimulationGraph+1 | No attempts yet | 1s | 128 MB | Judgeable |
| NetworkingGiven points and weighted candidate cable routes, compute the minimum total cable length needed to connect all points (minimum spanning tree). | Easy3 | Minimum spanning treeGraph+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Modulo SolitaireGiven a modulus m, up to 10 affine maps, and a start s0, find the fewest moves to reach 0. | Easy3 | BFSGraph | No attempts yet | 1s | 128 MB | Judgeable |
| Choose Your Own AdventureEach page is a node with two outgoing choices or a terminal ending; print the unique path from page 1 to the single HAPPY ending. | Easy3 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| The Great SaharaOn a fixed 54-triangle hex board, decide whether player one can move one pyramid to trap an opponent's pyramid immediately. | Easy3 | SimulationImplementation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Number of IslandsGiven a grid of land and sea cells with 8-directional adjacency, count the connected land components. | Easy3 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Red and BlackCount how many black tiles are reachable from a start tile in a small grid by moving up, down, left, and right. | Easy3 | DFSGraph+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Car TroubleGiven a directed graph of street ids with ring road 0, report streets that cannot reach 0 and streets that 0 cannot reach, preserving input order. | Easy3 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Connected or Not ConnectedGiven a graph with n sites and k edges, decide whether every site can reach every other. | Easy3 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Mining MapsParse each graph block, count distinct node names, and count distinct undirected tunnels including self-loops. | Easy3 | Hash mapGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Asteroid FieldFind the minimum number of moves from the top-left cell to the bottom-right cell in a grid, avoiding asteroid cells. | Easy3 | BFSGraph+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Breed AssignmentCount the breed assignments for N cows under same/different constraints, or report 0 if they conflict. | Easy3 | GraphBacktracking+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Daisy Chains in the FieldGiven an undirected graph of cows joined by ropes, list in ascending order every cow that cannot reach cow 1, or print 0 if all cows are connected to it. | Easy3 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Parcel DeliveryGiven a weighted undirected graph, find the minimum total edge weight along a path from barn 1 to barn N. | Easy3 | Shortest pathGraph | No attempts yet | 1s | 128 MB | Judgeable |
| 3D Space ExplorationCount connected groups of '*' blocks in an N x N x N grid, where blocks connect only across shared faces. | Easy3 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| The Leisurely StrollGiven a rooted tree of choice-nodes where leaf edges lead to pastures, find the maximum number of edges on any root-to-pasture path. | Easy3 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Invasion of the MilkweedSpread milkweed from a start cell to all eight neighbors each week and report the week it covers the last non-boulder cell. | Easy3 | BFSGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Feeding TimeGiven a W by H grid of grass and rock, find the size of the largest connected grass region using 8-directional adjacency. | Easy3 | DFSBFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Wheel RotationGiven N-1 belts that chain N pulleys from pulley 1, with each belt either straight (same direction) or crossed (reversed), find the rotation direction of pulley N. | Easy3 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Bad GrassCount connected components of nonzero cells in a grid, where two cells connect if they touch horizontally, vertically, or diagonally. | Easy3 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Best GrassCount clumps of # cells in a grid, where each clump is one cell or two orthogonally adjacent cells and different clumps never touch. | Easy3 | ArraySimulation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| S-TreesGiven an S-tree's variable ordering and terminal labels, evaluate the Boolean function for each supplied variable assignment. | Easy3 | TreeSimulation+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Shipping RoutesGiven warehouses and bidirectional shipping legs, answer each request with the cheapest cost, which is shipment size times the minimum number of legs times 100, or report no route. | Easy3 | GraphBFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Help the problem setterFor each test case, read a binary search tree on labels 1..n and print each node's frequency, computed bottom-up as 1 plus the sum of the frequencies of all its proper descendants. | Easy3 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| SurfingParse links out of HTML pages, print each link, then answer reachability queries between pages. | Easy3 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Making shortest-path test dataPrint the prescribed shortest-path test graph: a chain with a computed number of self-loops at vertex 0, plus Q queries from V-1 to 0. | Easy3 | ImplementationGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Graph that exceeds Dijkstra's counterPrint the exact constructed directed weighted graph that makes Floyd-Warshall finish while the lazy-deletion Dijkstra times out on one query. | Easy3 | GraphShortest path+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Attendance CheckGiven a permutation forming one cycle, find the student who responds last when the calling chain starts at student k. | Easy3 | ImplementationSimulation+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| Social Networking ApplicationGiven a friendship graph, answer queries asking whether two users lie in the same connected component. | Easy3 | Union-findGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Subdivision of KingdomSplit n towns (n even, n <= 26) into two halves of equal size so that the number of roads crossing between the halves is minimized. | Easy3 | Brute forceBit manipulation+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Computation of a Road Network PlanGiven the number of cities n and a target diameter d, print a specific tree: a path of length d with all remaining cities hung off its middle vertex. | Easy3 | TreeImplementation+1 | No attempts yet | 1s | 128 MB | Judgeable |
| The DanceFind the largest number of boy-girl pairs that can dance at once when each boy may only invite a girl he knows. | Easy3 | GraphDFS | No attempts yet | 1s | 128 MB | Judgeable |
| Network InvestmentFind the tree edge whose removal maximizes the product of the two component sizes. | Easy3 | DFSTree | No attempts yet | 1s | 128 MB | Judgeable |
| The HareFind the fewest knight jumps from the start cell to the burrow on a grid with blocked cells, or output NIE when unreachable. | Easy3 | BFSGraph+1 | No attempts yet | 1s | 512 MB | Judgeable |
| Rectangle ColoringCount the groups of overlapping rectangles where touching edges count as overlap and each group gets one color. | Easy3 | Union-findGeometry | No attempts yet | 1s | 128 MB | Judgeable |
| The SuspectsCount every student connected to student 0 through shared groups, since one suspect makes each joined group suspect. | Easy3 | Union-find | No attempts yet | 1s | 128 MB | Judgeable |
| Hauling materialCompute the cheapest directed route from the start to the destination for each road network. | Easy3 | Shortest pathGraph | No attempts yet | 1s | 128 MB | Judgeable |
| The Prague LinkCompute the largest shortest-path distance over all pairs of posts, or report that the network is disconnected. | Easy3 | Shortest pathGraph | No attempts yet | 1s | 128 MB | Judgeable |
| Robot in a MazeFind the fewest up, down, left, or right moves from S to any G in each grid maze, or report that no exit exists. | Easy3 | BFSMatrix | No attempts yet | 1s | 128 MB | Judgeable |
| CrankCount the boundary rooftops that can reach the boss by moving only to equal or lower adjacent buildings. | Easy3 | BFSGraph+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Strahler orderGiven a river DAG, compute its Strahler order at node M by processing nodes in topological order. | Easy3 | Topological sortGraph | No attempts yet | 1s | 128 MB | Judgeable |
| Who you knowFind the cheapest chain of introductions from politician 0 to politician M-1 in an undirected graph with edge weights 1 to 4, printing -1 when unreachable. | Easy3 | Shortest pathGraph | No attempts yet | 1s | 128 MB | Judgeable |
| Rainforest CanopyCount the groups of 1s connected through all eight neighbours in each square binary image. | Easy3 | DFSGraph+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Bi-coloringCount the two-colorings where every edge joins different colors, or report -1 when the graph is not bipartite. | Easy3 | BFSGraph | No attempts yet | 1s | 128 MB | Judgeable |
| Candy FactoryEach parent in a heap-ordered binary tree makes as many candies as the smaller child count, and the total subtracts consumed ingredients from all made candies. | Easy3 | TreeRecursion+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Knight MovesFind the fewest knight moves from K to X on a grid with blocked squares, or output -1 when unreachable. | Easy3 | BFSMatrix | No attempts yet | 1s | 128 MB | Judgeable |
| Elephant ShowCount the yellow tiles reachable from the elephant start by moving up, down, left, or right. | Easy3 | DFSMatrix | No attempts yet | 1s | 128 MB | Judgeable |
| Cracking Tree CodesGiven a tree and its leaf-stripping code with some entries erased, the program replays the encoding to recover the missing numbers. | Easy3 | SimulationTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Mystery Graph ColoringColor vertices 0 to V-1 with the smallest color unused by colored neighbors, then print the color count, the colors, and the loop counter. | Easy3 | GraphGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Complete Binary TreeReconstruct each level of a complete binary tree from its inorder visit order. | Easy3 | TreeRecursion | No attempts yet | 1s | 128 MB | Judgeable |
| Asteroids!Find the shortest 6-directional path through an N by N by N grid with blocked cells, or report that no route exists. | Easy3 | BFSMatrix | No attempts yet | 1s | 128 MB | Judgeable |
| Color WeaknessCount connected R, G, B regions in an N by N grid twice, once normally and once with R and G merged. | Easy3 | BFSMatrix | No attempts yet | 1s | 128 MB | Judgeable |
| Balance ScaleGiven pairwise heavier-than results, count for each object how many others have no implied comparison. | Easy3 | GraphDFS | No attempts yet | 1s | 256 MB | Judgeable |
| Minion WalkMark every grid cell reachable from the top-left corner, print the room as an ASCII table, and report whether the bottom-right cell is reachable. | Easy3 | BFSMatrix+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Neighborhoods in GraphsCount the distinct vertices at distance 1 or 2 from a query vertex in an undirected graph, excluding the vertex itself. | Easy3 | BFSGraph | No attempts yet | 1s | 256 MB | Judgeable |
| The Trojan HorseMark all cells visited by patrol routes on an h by w grid, then count 4-connected unvisited regions with at least s cells. | Easy3 | DFSSimulation+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Counting Communication GroupsCount the connected groups of camps whose circular communication areas touch or overlap. | Easy3 | Union-findGeometry | No attempts yet | 8s | 256 MB | Judgeable |
| Corn mazeStarting from the single entrance on the border, move through open cells in four directions and report the farthest shortest distance. | Easy3 | BFSMatrix | No attempts yet | 1s | 256 MB | Judgeable |
| Algorist ClubThe program gives each unfamiliar pair in input order the lowest free of max-degree-plus-one slots and prints zeros when a pair fits nowhere. | Easy3 | SimulationGraph | No attempts yet | 1s | 256 MB | Judgeable |
| Permutation CyclesCount the disjoint directed cycles in the permutation given in each test case. | Easy3 | GraphDFS | No attempts yet | 1s | 256 MB | Judgeable |
| Hyacinth frequency assignmentAssign one frequency to each edge of a tree by the stated DFS rule so each node uses at most two frequencies. | Easy3 | TreeDFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| DOM TV ChannelsPensioners switch the TV from each hated channel to the youngest hater's favorite, and you count switches until the channel stabilizes or repeats. | Easy3 | GraphSimulation | No attempts yet | 1s | 256 MB | Judgeable |
| Cable CleanupFor each test case, keep N minus 1 of the M cables that join N computers into one network and print how many cables go. | Easy3 | GraphMath | No attempts yet | 1s | 256 MB | Judgeable |
| Legacy CodeCount methods unreachable from any PROGRAM method given each method and its direct callers. | Easy3 | GraphBFS | No attempts yet | 1s | 256 MB | Judgeable |