Problems

Pick a problem and write your solution in the built-in editor. The judge runs it against real test cases while you watch, and the wider archive is open to read whenever you like.

Total results1,012 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
VirusCount how many computers other than computer 1 lie in computer 1's connected component of a small undirected graph.Easy2GraphBFS+1No attempts yet1s128 MBJudgeable
Leaf Nodes in a TreeGiven a tree by parent array, delete a node and all its descendants, then count how many leaf nodes remain.Easy3TreeDFS+1No attempts yet2s128 MBJudgeable
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.Easy3BacktrackingDFS+1No attempts yet2s128 MBJudgeable
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.Easy3DFSBFS+1No attempts yet2s128 MBJudgeable
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.Easy3BFSDFS+1No attempts yet2s128 MBJudgeable
Painted AreasCount connected components of 1-cells in a grid (4-directional adjacency) and output the count and the size of the largest component.Easy3BFSDFS+1No attempts yet2s128 MBJudgeable
Tree TraversalBuild a binary tree from parent-child input and print its preorder, inorder, and postorder traversals.Easy3TreeDFS+1No attempts yet2s128 MBJudgeable
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.Easy3GraphDFS+2No attempts yet1s128 MBJudgeable
Number of IslandsGiven a grid of land and sea cells with 8-directional adjacency, count the connected land components.Easy3GraphDFS+2No attempts yet1s128 MBJudgeable
Red and BlackCount how many black tiles are reachable from a start tile in a small grid by moving up, down, left, and right.Easy3DFSGraph+1No attempts yet1s128 MBJudgeable
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.Easy3GraphDFS+2No attempts yet1s128 MBJudgeable
Connected or Not ConnectedGiven a graph with n sites and k edges, decide whether every site can reach every other.Easy3GraphDFS+1No attempts yet1s128 MBJudgeable
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.Easy3GraphDFS+2No attempts yet1s128 MBJudgeable
3D Space ExplorationCount connected groups of '*' blocks in an N x N x N grid, where blocks connect only across shared faces.Easy3GraphDFS+2No attempts yet1s128 MBJudgeable
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.Easy3TreeDFS+2No attempts yet1s128 MBJudgeable
Feeding TimeGiven a W by H grid of grass and rock, find the size of the largest connected grass region using 8-directional adjacency.Easy3DFSBFS+2No attempts yet1s128 MBJudgeable
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.Easy3GraphDFS+2No attempts yet1s128 MBJudgeable
Bad GrassCount connected components of nonzero cells in a grid, where two cells connect if they touch horizontally, vertically, or diagonally.Easy3GraphDFS+2No attempts yet1s128 MBJudgeable
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.Easy3TreeDFS+2No attempts yet1s128 MBJudgeable
SurfingParse links out of HTML pages, print each link, then answer reachability queries between pages.Easy3GraphDFS+1No attempts yet1s128 MBJudgeable
Social Networking ApplicationGiven a friendship graph, answer queries asking whether two users lie in the same connected component.Easy3Union-findGraph+2No attempts yet1s128 MBJudgeable
The DanceFind the largest number of boy-girl pairs that can dance at once when each boy may only invite a girl he knows.Easy3GraphDFSNo attempts yet1s128 MBJudgeable
Network InvestmentFind the tree edge whose removal maximizes the product of the two component sizes.Easy3DFSTreeNo attempts yet1s128 MBJudgeable
Rainforest CanopyCount the groups of 1s connected through all eight neighbours in each square binary image.Easy3DFSGraph+1No attempts yet1s128 MBJudgeable
Elephant ShowCount the yellow tiles reachable from the elephant start by moving up, down, left, or right.Easy3DFSMatrixNo attempts yet1s128 MBJudgeable
Balance ScaleGiven pairwise heavier-than results, count for each object how many others have no implied comparison.Easy3GraphDFSNo attempts yet1s256 MBJudgeable
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.Easy3DFSSimulation+1No attempts yet1s256 MBJudgeable
Permutation CyclesCount the disjoint directed cycles in the permutation given in each test case.Easy3GraphDFSNo attempts yet1s256 MBJudgeable
Hyacinth frequency assignmentAssign one frequency to each edge of a tree by the stated DFS rule so each node uses at most two frequencies.Easy3TreeDFS+1No attempts yet1s256 MBJudgeable
One sheep... two sheep...Count the groups of # cells connected up, down, left, or right in each test grid.Easy3DFSGraph+1No attempts yet1s256 MBJudgeable
Pub-lic GoodColor each site pub or house with the specified ordered depth-first search so every site neighbors an opposite color, or print Impossible.Easy3DFSGraph+1No attempts yet1s256 MBJudgeable
Travel of AlphabetsCount all length-L walks on a letter grid and the distinct strings among them, discarding any word containing a, c, or m.Easy3BacktrackingDFS+1No attempts yet2s256 MBJudgeable
Relief SuppliesDecide whether any walk starting at intersection 1 in a directed graph can revisit an intersection.Easy3DFSGraphNo attempts yet2s256 MBJudgeable
Number of connected componentsCount the connected components of an undirected graph given its vertices and edges.Easy3GraphDFSNo attempts yet3s512 MBJudgeable
Twibet (Small)Starting from each monk in turn, count how many monks hear a whisper that spreads from a monk to all direct and indirect followers.Easy3GraphDFSNo attempts yet5s512 MBJudgeable
Binary treeGiven each node's parent in a binary tree with n up to 20, print the height (distance from the root) of every node.Easy3TreeDFSNo attempts yet2s512 MBJudgeable
Two-color coloringGiven an undirected multigraph, decide whether it is bipartite so its vertices can be colored with two colors.Easy3GraphBFS+1No attempts yet2s256 MBJudgeable
BannerCount connected groups of 1s in an M by N grid where cells touching in any of the eight directions belong to the same group.Easy3GraphDFS+2No attempts yet2s512 MBJudgeable
Paint bucketFlood fill a grid from one pixel, repainting all side-connected pixels sharing the clicked color with a new color, then print the grid.Easy3GraphBFS+2No attempts yet2s512 MBJudgeable
Trees and QueriesCount the vertices in the subtree of each queried node in a tree with a given root.Easy3TreeDFS+1No attempts yet1s128 MBJudgeable
Jelly Jump (Large)Given an N by N board where each cell holds a jump length, decide whether Jelly can travel from the top-left cell to the bottom-right cell moving only right or down.Easy3Dynamic programmingMatrix+2No attempts yet2s128 MBJudgeable
Thread TreeGiven n posts where each post names its parent post, print the messages in preorder with dots showing each post's depth.Easy3TreeDFS+1No attempts yet2s512 MBJudgeable
PotionGiven market prices and mixture recipes, compute the cheapest cost to produce one unit of the potion named LOVE.Medium4GraphDynamic programming+2No attempts yet2s128 MBJudgeable
Distance Between Tree NodesGiven a weighted tree and multiple node pairs, compute the path distance between each pair using tree traversal.Medium4TreeBFS+1No attempts yet2s128 MBJudgeable
Efficient HackingGiven directed trust edges between N computers, find all computers that, if hacked first, let the hacker reach the maximum possible number of computers.Medium4GraphBFS+1No attempts yet5s256 MBJudgeable
Age RelationsBuild a directed graph from age comparisons and answer queries about who is older using reachability through transitive relations.Medium4GraphDFS+1No attempts yet2s128 MBJudgeable
Police StationsGiven a directed graph and per-city build costs, find strongly connected components and sum the minimum cost city in each component.Medium4GraphDFS+1No attempts yet2s128 MBJudgeable
Downhill PathsCount the number of strictly decreasing height paths from the top-left to the bottom-right cell of a grid, moving only to adjacent cells, using memoized DFS.Medium4Dynamic programmingDFS+1No attempts yet2s128 MBJudgeable
Bipartite GraphFor several undirected graphs, determine whether each one can be 2-colored so that no edge joins two vertices of the same color.Medium4GraphBFS+1No attempts yet2s256 MBJudgeable
Painting Board Piece SizesGiven a grid with wall segments blocking movement between adjacent cells, find the largest and smallest connected region sizes using BFS or DFS.Medium4BFSDFS+2No attempts yet2s128 MBJudgeable
Team AssignmentSplit students into two groups using graph two-coloring so no pair who dislike each other lands on the same team, printing both groups.Medium4GraphBFS+1No attempts yet2s128 MBJudgeable
Diameter of a TreeGiven a weighted tree of up to 10,000 nodes rooted at node 1, compute the maximum-length path between any two nodes.Medium4TreeDFS+1No attempts yet2s128 MBJudgeable
Number Board JumpCount the distinct length-6 digit strings obtainable by starting anywhere on a 5x5 digit board and making five moves to adjacent cells.Medium4DFSBrute force+1No attempts yet2s128 MBJudgeable
Maximum Independent Set in a TreeGiven a weighted tree, compute a maximum weight independent set using tree DP and output the chosen vertices.Medium4Dynamic programmingTree+1No attempts yet2s128 MBJudgeable
Proving PropositionsGiven directed edges between letters, compute the transitive closure and print all reachable pairs excluding self-loops, sorted by letter order.Medium4GraphDFS+1No attempts yet2s128 MBJudgeable
Toy AssemblyCompute how many units of each basic part are needed to build one finished toy given a DAG of assembly quantities.Medium4GraphDFS+1No attempts yet1s128 MBJudgeable
Breaking CouplesOrient every edge of an undirected graph so each vertex's in-degree and out-degree differ by at most 1, which is always possible via an Euler-tour style pairing on connected components.Medium4GraphDFS+1No attempts yet2s128 MBJudgeable
Nearest Common AncestorGiven a rooted tree and two nodes, find their nearest common ancestor for each test case.Medium4TreeDFS+1No attempts yet1s128 MBJudgeable
Society MembersGiven nested society membership definitions with possible society-name references, compute the total number of distinct human members in the first listed society.Medium4GraphDFS+1No attempts yet1s128 MBJudgeable
CountdownGiven one family tree per test case, count for each person how many descendants sit exactly d generations below, then rank the top holders.Medium4GraphDFS+1No attempts yet1s128 MBJudgeable
Dominos 2Given directed edges between dominos and a set of manually pushed dominos, count how many dominos end up falling.Medium4GraphDFS+2No attempts yet1s128 MBJudgeable
DominosGiven a directed graph of domino toppling relations, find the minimum number of blocks to push by hand so that all blocks fall.Medium4GraphDFS+1No attempts yet1s256 MBJudgeable
Relative RelativesGiven Ted's age of 100 and each descendant's father name plus the father's age at the child's birth, compute every descendant's age and list them oldest first, ties broken by name.Medium4TreeDFS+2No attempts yet1s128 MBJudgeable
Image PerimetersGiven a grid and a click, find all X squares connected to the click by 8-direction adjacency and report the perimeter of that object.Medium4BFSDFS+2No attempts yet1s128 MBJudgeable
Oil DepositsCount connected components of oil pockets (@) in a grid where cells connect in all eight directions; input ends when m is 0.Medium4GraphDFS+2No attempts yet1s128 MBJudgeable
Winter FestivalGiven each person's single gift recipient, print every giving cycle in the order their first names appear in the input.Medium4GraphDFS+1No attempts yet1s128 MBJudgeable
Spreadsheet Circular ReferenceGiven spreadsheet cell formulas as lines, decide for each defined cell whether evaluating it leads to a circular reference, printing the cell name and circular or ok.Medium4GraphDFS+1No attempts yet1s128 MBJudgeable
HexGiven a Hex board of size n, decide whether Black, White, or nobody has a connecting path between the required edges.Medium4GraphDFS+1No attempts yet1s128 MBJudgeable
Message RelayEach cow forwards to at most one other cow; count cows whose messages never reach a cycle and instead stop.Medium4GraphDFS+1No attempts yet1s128 MBJudgeable
Space ExplorationCount the connected components of asterisk cells in an N x N grid, where cells connect only along shared edges, not corners.Medium4GraphDFS+2No attempts yet1s128 MBJudgeable
Meeting PlaceGiven a rooted tree and M queries, report the lowest common ancestor of two nodes for each query.Medium4TreeDFS+2No attempts yet1s128 MBJudgeable
Guarding the FarmCount connected groups of equal-altitude cells, using 8-direction adjacency, that are surrounded only by lower altitude or the map edge.Medium4GraphDFS+2No attempts yet1s128 MBJudgeable
Oh Those RollersRollers touch when the distance between centers equals the sum of radii. Starting from the roller at the origin, follow the chain to the roller that drives no other and print its coordinates.Medium4GraphDFS+2No attempts yet1s128 MBJudgeable
Cow PicnicGiven K starting pastures and a directed graph, count the pastures reachable from every one of the K starting positions.Medium4GraphDFS+2No attempts yet1s128 MBJudgeable
The die is castGiven a grid picture of dice drawn with background, die, and dot pixels, count the connected dot regions inside each connected die region and print the counts sorted.Medium4DFSBFS+2No attempts yet1s128 MBJudgeable
N-Credible MazesGiven a dimension n and a list of paths between adjacent lattice points, decide if start and end coordinates are connected.Medium4GraphDFS+2No attempts yet1s128 MBJudgeable
Mapping the RouteSimulate a west, north, east, south backtracking search on a small walled grid, number the route cells, mark other visited cells with ???, and draw the maze.Medium4DFSBacktracking+2No attempts yet1s128 MBJudgeable
Who is taller?Given comparisons stating x is taller than y, decide whether p is taller than q, q is taller than p, or neither is known.Medium4GraphDFS+1No attempts yet1s128 MBJudgeable
Floor PlanGiven a grid of walls and floor cells, count connected rooms, sort them by size, floor as many of the largest rooms as the wood supply allows, and report how many rooms got flooring plus the leftover wood.Medium4DFSSorting+2No attempts yet1s128 MBJudgeable
Packet RoutingGiven a tree with weighted edges connecting N computers, compute the travel time along the unique path between each query pair of computers.Medium4TreeDFS+2No attempts yet1s128 MBJudgeable
Disk TreeGiven full directory paths, rebuild the tree and print every directory name on its own line, indented by depth, with siblings in ASCII order.Medium4TrieSorting+1No attempts yet1s128 MBJudgeable
Holiday GiftsAssign one of two priced gifts to each node of a rooted tree so no two adjacent employees share a gift, minimizing total cost.Medium4TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Handong the Salesman!Given a tree, start at node 1 and visit m listed nodes in order, summing the tree distances between consecutive stops.Medium4GraphTree+2No attempts yet1s128 MBJudgeable
PolygonGiven a convex polygon and a set of non-crossing diagonals, report the largest number of sides among the pieces the diagonals divide it into.Medium4GraphDFS+2No attempts yet1s128 MBJudgeable
DyzioParse a 0/1 description of recursive halving cuts and output the cut count at which the first shortest piece appears.Medium4TreeDFS+2No attempts yet1s128 MBJudgeable
Odd-Length CycleFor each of t undirected graphs, decide whether it contains an odd-length cycle (equivalently, is not bipartite).Medium4GraphBFS+1No attempts yet1s128 MBJudgeable
BanquetFind how many round tables are needed by counting the cycles in the left-neighbor links.Medium4GraphDFSNo attempts yet1s512 MBJudgeable
MerchantFind the simple path, possibly empty, in a weighted tree whose edge weights sum to the largest value.Medium4TreeDynamic programming+1No attempts yet1s128 MBJudgeable
Snow PlowsFind the fewest trails that cover every street exactly once by counting odd-degree intersections in each connected part.Medium4GraphDFSNo attempts yet3s128 MBJudgeable
Circle DanceFind the largest want-link cycle in which each girl is disliked by fewer than half of the members.Medium4GraphDFSNo attempts yet1s128 MBJudgeable
ActorsDecide whether every role can be filled by a distinct available actor who rehearsed it.Medium4GraphDFSNo attempts yet1s128 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
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
RankCount the players that lie on a directed win cycle built from the game results.Medium4GraphDFSNo attempts yet2s1024 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
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
Man in the MiddleDecide whether removing some single person disconnects the connected friendship network.Medium4DFSGraphNo attempts yet3s256 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