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
JuiceGiven a rooted tree with cord capacities and house demands, choose which houses to power so that flow through each cord stays within capacity and the count is maximized.Medium6TreeDFS+2No attempts yet2s128 MBJudgeable
Cuckoo HashingGiven each word's two hash slots, decide whether inserting all words in order avoids an infinite cuckoo eviction chain.Medium6GraphDFS+1No attempts yet1s128 MBJudgeable
My Cousin ObamaGiven a forest of parent links, find the ancestor path from A0 to B0 that passes through as few mothers as possible.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Starry NightFind 8-connected star clusters in a grid and assign the same letter to clusters that match under rotation and reflection.Medium6DFSMatrix+2No attempts yet1s128 MBJudgeable
Ants ColonyBuild a weighted tree where each new node attaches to an earlier one, then answer distance queries between pairs of nodes.Medium6TreeDFS+2No attempts yet2s128 MBJudgeable
Another CrisisGiven a company tree and a threshold T percent, find the minimum number of leaf workers who must petition so that a petition reaches the root.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
ICPC Strikes AgainGiven a DAG of task dependencies, basic significances, and which employees perform which tasks, compute each employee's salary as the sum of significances of tasks they perform that no other task they perform depends on.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
This Sentence is FalseEach sentence claims another sentence is true or false; decide whether a consistent assignment exists and, if so, maximize the number of true sentences.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
HorseshoesOn an N x N grid (N at most 5) of parentheses, find the longest walk from the top-left cell, visiting each cell at most once, whose collected characters form a run of '(' followed by an equally long run of ')'.Medium6DFSBacktracking+2No attempts yet1s128 MBJudgeable
Nearby CowsOn a tree of N fields with C(i) cows at each field, report for every field the total cows within distance K, where K is at most 20.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Visiting CowsGiven a tree with N vertices, choose the largest set of vertices with no two adjacent, which is the maximum independent set on a tree.Medium6TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Chocolate MilkGiven a directed tree with N-1 edges where all flow reaches one sink, list every non-source node that lies on every root-to-sink path.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Great Cow GatheringPick a node of a weighted tree with node weights as the gathering point, and minimize the sum of cow count times distance to that node.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Time TravelProcess add, pop, and rewind-to-earlier-query operations on a recorded list, printing the last element after each query.Medium6StackTree+2No attempts yet1s128 MBJudgeable
Trick or Treat on the FarmEach stall has one outgoing next pointer. For every starting stall, count how many distinct stalls the walk visits before it first revisits a stall.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Secret MessageGiven M binary messages and N binary codewords, count for each codeword how many messages share a prefix relation with it in either direction.Medium6TrieString+2No attempts yet1s128 MBJudgeable
Watering Plan Check 3Given a grid land divided into fields and a proposed sprinkler plan drawn with letters and underscores, verify the plan and count holes drilled in fences.Medium6ImplementationSimulation+2No attempts yet1s128 MBJudgeable
Cell Phone NetworkGiven a tree of N pastures, choose the fewest vertices so that every vertex is chosen or adjacent to a chosen one.Medium6TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Cow TrafficIn a DAG where every edge goes from a lower to a higher numbered node, count how many source-to-barn paths cross each edge and output the maximum.Medium6GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Party at Hali-BulaGiven a company hierarchy tree, find the largest set of employees with no boss and employee both chosen, and report whether that maximum set is unique.Medium6TreeDynamic programming+2No attempts yet1s128 MBJudgeable
NetworkGiven an undirected connected graph, count the articulation points whose removal disconnects some other pair of vertices. Input is line-oriented and ends with 0.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Synchronous DesignGiven a circuit of synchronous and asynchronous nodes with delays, report whether it has an asynchronous cycle, exceeds the clock period between synchronous nodes, or is a valid synchronous design.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
SpreadsheetEach cell holds an integer or a sum formula referring to other cells; evaluate all formulas and print the resulting grid, with no reference cycles.Medium6GraphTopological sort+2No attempts yet1s128 MBJudgeable
Alien SecurityGiven a directed graph with entry at room 0 and a target ET room, find the room closest to the target such that every path from 0 to the target passes through it, excluding the target itself.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Fiber NetworkFor each query in a directed multigraph where every edge is labeled with a set of companies, list the companies that have a path from A to B using only their own edges.Medium6GraphBFS+2No attempts yet1s128 MBJudgeable
ElectricityGiven an undirected graph, find the maximum number of connected components formed when any single vertex is removed.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
A Model RailroadPlace a non-self-crossing path of straight and curved rails in a small grid from a bottom connection to a top connection, maximizing the number of cells used.Medium6DFSBacktracking+2No attempts yet1s128 MBJudgeable
Tree PruningGiven a rooted binary tree with colored nodes, prune subtrees to make the whites minus blacks equal exactly D, minimizing the number of prunes.Medium6TreeDynamic programming+2No attempts yet2s512 MBJudgeable
HerdingPlace the fewest traps on a grid of arrows so that a cat starting anywhere and following arrows forever eventually enters a trapped cell.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
FriendsEach student points to exactly one friend, forming directed cycles; for each query, report whether two students lie on the same cycle and the forward distance between them.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Game Show MathInsert +, -, *, / between the given numbers in order, left to right, so the running value hits the target; output the smallest expression or NO EXPRESSION.Medium6DFSBacktracking+1No attempts yet2s128 MBJudgeable
Mountain PassageFind the minimum count of steps that touch an elevation above the start height, moving on an n by n grid with height changes limited to 2 per step.Medium6GraphShortest path+2No attempts yet1s128 MBJudgeable
Tree IsomorphismGiven two rooted trees in pre-order with '#' closing each node's child list, decide whether the trees are isomorphic ignoring node labels.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
JourneyGiven a weighted tree, a start city k, and a set of target cities, find the length of the shortest walk from k that visits every target at least once.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Heating MainCount the ways to lay a single non-crossing path of four fixed pipe shapes from the top-left top side to the bottom-right right side, respecting fixed pipes and blocked garden cells on a grid of at most 10 by 10.Medium6BacktrackingDFS+2No attempts yet1s128 MBJudgeable
FireworksA firework splits into two 45-degree branches after each vertical stage; count the distinct grid squares colored across all stages.Medium6SimulationDFS+2No attempts yet2s1024 MBJudgeable
Turning a TreeReroot a given ordered tree at a specified leaf so the counter-clockwise order of neighbors at each node stays the same, then print the new tree.Medium6TreeDFS+2No attempts yet1s1024 MBJudgeable
PoliticiansGiven ratio relations between politicians that form a connected comparison graph, find the most and least important and their importance ratio to two decimals.Medium6GraphDFS+2No attempts yet1s1024 MBJudgeable
LiarsGiven claims that candidate a says candidate b lies or tells the truth, decide whether candidates can be split into liars and truth-tellers consistently.Medium6GraphBFS+2No attempts yet1s1024 MBJudgeable
Monthly Railway PassA graph has train and bus edges. Count cities from which every other city is reachable using any number of train edges and at most one bus edge.Medium6GraphDFS+1No attempts yet2s1024 MBJudgeable
UnfoldungFor each cube-built surface, decide whether its graph splits along cut edges, and if not, whether the surface can be unfolded flat.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Dolphin PoolGiven up to 20 circles with disjoint centers, count the bounded regions outside all circles that the circles enclose.Medium6GeometryGraph+1No attempts yet1s128 MBJudgeable
A Knight's JourneyFind the lexicographically smallest knight's tour that visits every square of a rectangular board with at most 26 squares exactly once.Medium6BacktrackingDFS+2No attempts yet1s128 MBJudgeable
Dory's PhonebookGiven a dictionary of words and a phone number, find every encoding of the number as a space-separated sequence of dictionary words, sorted lexicographically.Medium6TrieBacktracking+2No attempts yet1s128 MBJudgeable
BonsaiRoot a weighted tree and cut edges of minimum total weight so that no original leaf stays connected to the root.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Hiring the CrewGiven a directed graph of sailor demands, find the smallest non-empty vertex set closed under outgoing edges.Medium6GraphDFSNo attempts yet4s64 MBJudgeable
Playing With DominoGiven up to 1000 dominoes with faces numbered 0 to 6, find the largest number of tiles that can be linked in a single chain where touching squares match.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Transitive ClosureCount off-diagonal pairs (X, Y) with a directed path from X to Y in a graph of up to 2500 vertices and 10000 edges.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
SpreadsheetEvaluate a small 9x26 spreadsheet where each cell holds an integer expression with +, -, *, / and cell references, reporting 1000000 if cell A1 is part of a circular reference.Medium6ImplementationDFS+2No attempts yet1s128 MBJudgeable
Jack's SocksGiven an undirected graph of similar socks, decide whether a perfect matching exists and is unique, and print that matching if it is.Medium6GraphDFS+2No attempts yet1s512 MBJudgeable
SpeleologyGiven a DAG where chambers are numbered top to bottom, find the maximum number of downward paths from chamber 1 to chamber n that use distinct first corridors and distinct last corridors.Medium6GraphDynamic programming+2No attempts yet3s512 MBJudgeable
Three-Coloring of Binary TreesGiven a binary tree as a digit specification, color each node red, green, or blue so adjacent nodes differ and siblings differ, then report the maximum and minimum number of green nodes.Medium6TreeDFS+2No attempts yet3s128 MBJudgeable
MatchingsGiven a tree, compute the size of its maximum matching and count how many maximum matchings exist, modulo m.Medium6Dynamic programmingTree+2No attempts yet3s128 MBJudgeable
Cube of a GraphCount vertices, adjacent pairs, and triangles whose incident edges are all nontrivial bridges in a connected graph.Medium6GraphDFS+1No attempts yet1s128 MBJudgeable
Conference TableDecide whether pairs of majors from each university can sit in a ring so paired researchers sit together and neighbors share a major.Medium6GraphDFSNo attempts yet1s128 MBJudgeable
Jill's Tour PathsList every simple route from the start village to the destination within the distance limit, ordered by length then village order.Medium6BacktrackingDFS+2No attempts yet1s128 MBJudgeable
BoggleFind all dictionary words on each 4x4 Boggle board with 8-direction steps without reuse, then report the total score, longest word, and word count.Medium6TrieDFS+1No attempts yet10s512 MBJudgeable
Welcome PartySplit interns into the fewest teams where each team shares one first-name or last-name initial.Medium6GraphDFSNo attempts yet1s128 MBJudgeable
Placing RooksPlace as many rooks as possible on an N by N board with pawns so no two share a row or column without a pawn between them.Medium6GraphDFSNo attempts yet1s128 MBJudgeable
Friendship GraphDecide up to 200000 reachability queries on a directed graph with 2000 vertices, printing 1 when Y is reachable from X.Medium6GraphDFS+2No attempts yet2s128 MBJudgeable
Mirror FieldCount the most reflections a border beam makes bouncing through a grid of diagonal mirrors, or report -1 if it loops forever.Medium6GraphDFSNo attempts yet1s128 MBJudgeable
Dropping DirectionsPlace the fewest directing signs at 4-way intersections so a walker who otherwise goes straight reaches the goal from any start.Medium6GraphDFSNo attempts yet2s256 MBJudgeable
Irrigation LinesOpen the fewest row and column lines so every planted cell shares a row or column with an open line.Medium6GraphDFS+1No attempts yet1s256 MBJudgeable
Sky CitiesAdd the fewest bridges so the connected cities stay connected after any single bridge fails, and print the pairs fixed by the leaf-pairing rule.Medium6DFSGraph+1No attempts yet1s256 MBJudgeable
NAFTAFor each K from 1 to S, drill up to K whole columns to drain every touched oil pool and maximize the collected oil.Medium6Dynamic programmingIntervals+1No attempts yet2s512 MBJudgeable
Chicken JoggersPlace the fewest extra lamps so every trail a jogger who starts at intersection 1 and returns after exactly S meters could use has a lamp on one end.Medium6Dynamic programmingTree+1No attempts yet1s256 MBJudgeable
Absurdistan Roads IIIEach city picks one of its incident roads so every road is picked once and the resulting neighbor list is lexicographically smallest.Medium6GraphGreedy+1No attempts yet2s256 MBJudgeable
Farthest node in a weighted treeFor every node of a weighted tree with up to 50000 nodes, print its distance to the farthest node.Medium6TreeDFSNo attempts yet1s256 MBJudgeable
Odd Cycle in a Directed GraphGiven a directed graph, decide whether it contains an odd directed cycle and output the smallest vertex of a strongly connected component that holds one.Medium6GraphBFS+1No attempts yet3s256 MBJudgeable
Robots and the Oil Transportation SystemTwo robots start at given stations and cover opposite ends of one trunk pipe, minimizing the slower robot travel time.Medium6Shortest pathDFS+1No attempts yet2s256 MBJudgeable
Max FlowCount how many of the K given tree paths pass through each stall and report the largest count.Medium6TreePrefix sum+1No attempts yet2s512 MBJudgeable
The Bored Traveling Salesman (Small)Choose a start city and a depth-first ticket tour of the graph so the concatenated first-visit ZIP codes form the smallest number.Medium6BacktrackingDFS+1No attempts yet5s512 MBJudgeable
Treasure Chests (Small)Open all N chests in the lexicographically smallest valid order using keys found inside chests, or report IMPOSSIBLE.Medium6BacktrackingDFS+2No attempts yet5s512 MBJudgeable
Mixing Bowls (Small)Given a recipe tree of mixtures, find the minimum number of bowls needed by choosing the order of preparation.Medium6TreeDFS+1No attempts yet5s512 MBJudgeable
King (Small)On a board of at most 16 squares with burned cells, a king moves to unvisited neighbors; decide who wins under optimal play.Medium6Game theoryDFS+1No attempts yet5s512 MBJudgeable
Modern Art PlagiarismDecide whether the smaller tree is isomorphic to some subtree cut from the larger tree.Medium6TreeDFS+1No attempts yet50s512 MBJudgeable
Tree CountryCount the subsets of K vertices in a tree that form a connected subtree, modulo 1e9+7.Medium6Dynamic programmingTree+2No attempts yet2s512 MBJudgeable
Happy TreeFind the minimum number of leaves to remove so that no remaining vertex has a descendant whose path distance exceeds that descendant's value.Medium6TreeDFS+1No attempts yet2s512 MBJudgeable
A Dark Flame Dragon Sleeps in My Left HandFor each node in a weighted tree, find the distance to the farthest other node (the tree's eccentricity).Medium6TreeDFS+1No attempts yet2s512 MBJudgeable
Sum of subtree sizesCount all connected subgraphs of a tree and output the sum of their vertex counts modulo 1e9+7.Medium6TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Domain clustersGiven a directed graph of domains, find the size of the largest set in which every domain can reach every other domain.Medium6GraphDFS+2No attempts yet2s512 MBJudgeable
TreeGiven a rooted tree, process a mix of edge deletions and connectivity queries in order, answering YES or NO for each query.Medium6Union-findTree+2No attempts yet2s512 MBJudgeable
Word Puzzle 2Given a 5x5 letter grid and up to 20000 dictionary words, count how many words can be traced through adjacent cells without reusing a cell.Medium6DFSBacktracking+1No attempts yet2s128 MBJudgeable
Fighting cancerGiven two trees on atoms 1..N, decide whether they are isomorphic as unlabeled graphs and print S or N.Medium6TreeDFS+1No attempts yet2s512 MBJudgeable
Come and GoGiven a mixed graph of one-way and two-way streets, decide whether every pair of intersections is mutually reachable.Medium6GraphDFS+1No attempts yet2s512 MBJudgeable
Free FigurinesGiven two valid nesting configurations of n matryoshka dolls, find the minimum number of place and take-out moves to transform one into the other.Medium6TreeGreedy+1No attempts yet1s512 MBJudgeable
Cactus ConstructionGiven a cactus as edge-disjoint paths, simulate the fixed recursive procedure that emits join, recolor, and connect operations assembling it with four colors.Medium6GraphDFS+2No attempts yet2s512 MBJudgeable
The Longest Travel RouteGiven a directed weighted graph with at most 18 cities, find the maximum total length of a simple path from city 0 to city n-1.Medium6Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
Phonomenal ReviewsGiven a tree and a set of M marked nodes, find the minimum number of edges Jo must walk to visit every marked node, starting anywhere.Medium6TreeDFS+2No attempts yet2s512 MBJudgeable
CoggleGiven a 5x5 letter grid and a dictionary, count how many dictionary words can be traced through adjacent cells without reusing a cell.Medium6BacktrackingTrie+1No attempts yet1s512 MBJudgeable
RidgeCount grid cells where rain falling on that cell alone eventually drains to more than one local minimum.Medium6GraphDFS+1No attempts yet2s512 MBJudgeable
Where's Bessie?Given an N x N grid of colors (N up to 20), count the rectangular sub-grids where exactly two colors appear, one forming one connected region and the other forming two or more, and that are not contained in any other such rectangle.Medium6ImplementationBrute force+1No attempts yet2s512 MBJudgeable
Marbles on the treeGiven a rooted ordered binary tree, find the leaf where the K-th marble stops, where each marble at a two-child node goes to the left if left subtree has at most the right subtree's resting marbles, else right.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
KUBC League (Small)Given a tournament on N players, find the longest simple path starting at player 1 and output the lexicographically smallest such path.Medium6GraphDFS+2No attempts yet1s256 MBJudgeable
Defend the CTP!!!Given a directed graph and many queries C, decide for each C whether 1 can reach C and C can reach N.Medium6GraphDFS+2No attempts yet2s256 MBJudgeable
Crush FeverOn an N by M grid of 5 piece kinds, choose 3 taps; each tap clears the connected same-kind group of the tapped cell and scores size squared, with pieces falling down after each tap. Maximize total points.Medium6DFSBrute force+2No attempts yet1.5s512 MBJudgeable
Googlements (Large)Count how many googlement strings could have decayed, through zero or more steps, into a given observed googlement.Medium6GraphDFS+2No attempts yet5s512 MBJudgeable
Tae and Dotori split a chocolate barCount assignments of U cells to T or D so each person's region is connected, the sizes differ by at most K, and neither region contains a 2x2 block.Medium6BacktrackingDFS+2No attempts yet2s512 MBJudgeable
Game MapGiven an undirected connected graph, find the longest simple path where the degree of each successive vertex strictly increases.Medium6GraphDynamic programming+2No attempts yet1s512 MBJudgeable
Go around the LabyrinthDecide whether a walk from the top-left corner can visit the other three corners and come back, where each non-entrance room collapses after one visit.Medium6GraphDFS+2No attempts yet2s512 MBJudgeable