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
| Title | Level | Topics | Solved | Time limit | Memory limit | Judge |
|---|---|---|---|---|---|---|
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| One sheep... two sheep...Count the groups of # cells connected up, down, left, or right in each test grid. | Easy3 | DFSGraph+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Easy3 | DFSGraph+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Easy3 | BacktrackingDFS+1 | No attempts yet | 2s | 256 MB | Judgeable |
| Relief SuppliesDecide whether any walk starting at intersection 1 in a directed graph can revisit an intersection. | Easy3 | DFSGraph | No attempts yet | 2s | 256 MB | Judgeable |
| Number of connected componentsCount the connected components of an undirected graph given its vertices and edges. | Easy3 | GraphDFS | No attempts yet | 3s | 512 MB | Judgeable |
| 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. | Easy3 | GraphDFS | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Easy3 | TreeDFS | No attempts yet | 2s | 512 MB | Judgeable |
| Two-color coloringGiven an undirected multigraph, decide whether it is bipartite so its vertices can be colored with two colors. | Easy3 | GraphBFS+1 | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Easy3 | GraphDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Easy3 | GraphBFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Trees and QueriesCount the vertices in the subtree of each queried node in a tree with a given root. | Easy3 | TreeDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Easy3 | Dynamic programmingMatrix+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Thread TreeGiven n posts where each post names its parent post, print the messages in preorder with dots showing each post's depth. | Easy3 | TreeDFS+1 | No attempts yet | 2s | 512 MB | Judgeable |
| PotionGiven market prices and mixture recipes, compute the cheapest cost to produce one unit of the potion named LOVE. | Medium4 | GraphDynamic programming+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Distance Between Tree NodesGiven a weighted tree and multiple node pairs, compute the path distance between each pair using tree traversal. | Medium4 | TreeBFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium4 | GraphBFS+1 | No attempts yet | 5s | 256 MB | Judgeable |
| Age RelationsBuild a directed graph from age comparisons and answer queries about who is older using reachability through transitive relations. | Medium4 | GraphDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Police StationsGiven a directed graph and per-city build costs, find strongly connected components and sum the minimum cost city in each component. | Medium4 | GraphDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium4 | Dynamic programmingDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Bipartite GraphFor several undirected graphs, determine whether each one can be 2-colored so that no edge joins two vertices of the same color. | Medium4 | GraphBFS+1 | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium4 | BFSDFS+2 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium4 | GraphBFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium4 | TreeDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium4 | DFSBrute force+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Maximum Independent Set in a TreeGiven a weighted tree, compute a maximum weight independent set using tree DP and output the chosen vertices. | Medium4 | Dynamic programmingTree+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Proving PropositionsGiven directed edges between letters, compute the transitive closure and print all reachable pairs excluding self-loops, sorted by letter order. | Medium4 | GraphDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Toy AssemblyCompute how many units of each basic part are needed to build one finished toy given a DAG of assembly quantities. | Medium4 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | GraphDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Nearest Common AncestorGiven a rooted tree and two nodes, find their nearest common ancestor for each test case. | Medium4 | TreeDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Society MembersGiven nested society membership definitions with possible society-name references, compute the total number of distinct human members in the first listed society. | Medium4 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| CountdownGiven one family tree per test case, count for each person how many descendants sit exactly d generations below, then rank the top holders. | Medium4 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Dominos 2Given directed edges between dominos and a set of manually pushed dominos, count how many dominos end up falling. | Medium4 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| DominosGiven a directed graph of domino toppling relations, find the minimum number of blocks to push by hand so that all blocks fall. | Medium4 | GraphDFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | BFSDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Oil DepositsCount connected components of oil pockets (@) in a grid where cells connect in all eight directions; input ends when m is 0. | Medium4 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Winter FestivalGiven each person's single gift recipient, print every giving cycle in the order their first names appear in the input. | Medium4 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| HexGiven a Hex board of size n, decide whether Black, White, or nobody has a connecting path between the required edges. | Medium4 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Message RelayEach cow forwards to at most one other cow; count cows whose messages never reach a cycle and instead stop. | Medium4 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Space ExplorationCount the connected components of asterisk cells in an N x N grid, where cells connect only along shared edges, not corners. | Medium4 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Meeting PlaceGiven a rooted tree and M queries, report the lowest common ancestor of two nodes for each query. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Guarding the FarmCount connected groups of equal-altitude cells, using 8-direction adjacency, that are surrounded only by lower altitude or the map edge. | Medium4 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Cow PicnicGiven K starting pastures and a directed graph, count the pastures reachable from every one of the K starting positions. | Medium4 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | DFSBFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| N-Credible MazesGiven a dimension n and a list of paths between adjacent lattice points, decide if start and end coordinates are connected. | Medium4 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | DFSBacktracking+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | GraphDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | DFSSorting+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Packet RoutingGiven a tree with weighted edges connecting N computers, compute the travel time along the unique path between each query pair of computers. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | TrieSorting+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | TreeDynamic programming+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Handong the Salesman!Given a tree, start at node 1 and visit m listed nodes in order, summing the tree distances between consecutive stops. | Medium4 | GraphTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| DyzioParse a 0/1 description of recursive halving cuts and output the cut count at which the first shortest piece appears. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Odd-Length CycleFor each of t undirected graphs, decide whether it contains an odd-length cycle (equivalently, is not bipartite). | Medium4 | GraphBFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| BanquetFind how many round tables are needed by counting the cycles in the left-neighbor links. | Medium4 | GraphDFS | No attempts yet | 1s | 512 MB | Judgeable |
| MerchantFind the simple path, possibly empty, in a weighted tree whose edge weights sum to the largest value. | Medium4 | TreeDynamic programming+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Snow PlowsFind the fewest trails that cover every street exactly once by counting odd-degree intersections in each connected part. | Medium4 | GraphDFS | No attempts yet | 3s | 128 MB | Judgeable |
| Circle DanceFind the largest want-link cycle in which each girl is disliked by fewer than half of the members. | Medium4 | GraphDFS | No attempts yet | 1s | 128 MB | Judgeable |
| ActorsDecide whether every role can be filled by a distinct available actor who rehearsed it. | Medium4 | GraphDFS | No attempts yet | 1s | 128 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 |
| 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 |
| RankCount the players that lie on a directed win cycle built from the game results. | Medium4 | GraphDFS | No attempts yet | 2s | 1024 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 |
| 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 |
| Man in the MiddleDecide whether removing some single person disconnects the connected friendship network. | Medium4 | DFSGraph | No attempts yet | 3s | 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 |