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 results837 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Wealthy FamilyGiven a rooted tree with a weight on each node, pick exactly k nodes with no ancestor relation between any two, maximizing the total weight, over multiple test cases.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Let's Go to the MoviesEach family is a parent with children, and tickets are either singles or family tickets (one parent plus any subset of their own children). Find the arrangement minimizing cost, breaking ties by fewest tickets.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Type PrinterFind the minimum number of add, remove, and print operations to type N distinct words on a printer that keeps a single editable string, with any print order allowed.Medium7TrieDFS+2No attempts yet1s128 MBJudgeable
The Lightest MobileGiven a tree of balanced rods with integer lever ratios, assign positive integer masses to all weights so every rod balances and the total mass is minimized.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
AcquapiaMultiple test cases give several river trees; for each city pair, report whether a route exists and, if so, the unique city where the ship must switch from upstream to downstream.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Running Away From the BarnFor every node in a weighted tree rooted at node 1, count the descendants within total distance L along the downward path, including the node itself.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Cow CalisthenicsRemove exactly S edges from a tree so that the largest diameter among the resulting components is as small as possible, and output that minimum diameter.Medium7TreeBinary search+2No attempts yet2s128 MBJudgeable
Tree DecorationPlace a minimum-cost number of ornaments on each node of a rooted tree so every subtree holds at least its required count, given per-node unit costs.Medium7TreeGreedy+2No attempts yet1s128 MBJudgeable
SolderingGiven a tree, cover its edges with paths (wires) that may meet at soldered points, minimizing the sum of squared path lengths.Medium7TreeDynamic programming+1No attempts yet2s128 MBJudgeable
Slowing downFor each cow in order, count how many pastures already occupied by earlier cows lie on the tree path from node 1 to that cow's pasture.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Cow PoliticsGiven a tree with each node belonging to one of K parties, find the diameter (greatest distance between any two nodes) of the nodes in each party.Medium7TreeDFS+2No attempts yet2s128 MBJudgeable
Corrupted BSTGiven a binary tree with distinct integer keys, find the minimum number of node keys to change so the tree satisfies the BST ordering, keeping its shape fixed.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
DehuffGiven a sample string and its full binary encoding, reconstruct the unique prefix-code table for the alphabet, or report several possible tables.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
ExpressionsGiven a postfix expression, produce another postfix expression that the same algorithm evaluates to the same value when a queue replaces the stack.Medium7StackQueue+2No attempts yet1s128 MBJudgeable
Teams that can winGiven n teams and n-1 desired games, count the teams that can be champion under some valid single-elimination schedule that plays every listed game.Medium7GraphTree+2No attempts yet1s128 MBJudgeable
Huffman's GreedWe build the optimal binary search tree for weighted key and gap frequencies, minimizing weighted comparison counts.Medium7Dynamic programmingTree+2No attempts yet1s128 MBJudgeable
Binary Search Heap ConstructionGiven label/priority pairs, build the unique treap (a binary search tree on labels and a max-heap on priorities) and print it in nested parenthesized form.Medium7TreeStack+2No attempts yet1s128 MBJudgeable
Phylogenetic Trees InheritedGiven leaf sequences of a complete binary tree, label internal nodes to minimize the sum of Hamming distances along edges, and output the lexicographically smallest optimal root sequence with its cost.Medium7Dynamic programmingTree+2No attempts yet1s128 MBJudgeable
TourneyMaintain a single-elimination bracket of 2^N players under point updates, and answer queries about the winner's position and how many rounds a given player wins.Medium7TreeSegment tree+2No attempts yet2s512 MBJudgeable
LHCGiven a tree, find the maximum cycle length obtainable by adding one edge, and count the vertex pairs that achieve it.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
MobileDecide whether two mobiles, given as rooted binary structures with negated weight labels, can be rotated to look identical.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Pyramid Message SchemeGiven a chronological list of message recipients from a sequential tree traversal, reconstruct the tree and compute the time saved by a parallel traversal.Medium7TreeStack+2No attempts yet1s128 MBJudgeable
The Great Spamway StrikeChoose a rooted tree over zombies with allowed bidirectional links, minimizing the round-trip time for a gather broadcast that includes each node's per-message read lag.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
S and KGiven binary trees written with S and K, repeatedly apply the two rewrite rules until no rule fires, then print the final tree string.Medium7ImplementationSimulation+2No attempts yet3s128 MBJudgeable
BSP TreesBuild a BSP tree by inserting p slanted planes into the xz-plane, assign n polygons to leaf regions, then print objects in the drawing order the tree induces.Medium7GeometryTree+2No attempts yet1s128 MBJudgeable
QuadTreesGiven pre-order strings of two quadtrees for N x N binary images, count the nodes in the quadtree of their pixelwise AND intersection, collapsing uniform quadrants.Medium7TreeDivide and conquer+2No attempts yet1s128 MBJudgeable
Uniform SubtreesGiven a parenthesis-encoded tree, list every distinct uniform subtree (same child count at each depth) in lexicographic order.Medium7TreeDFS+2No attempts yet3s128 MBJudgeable
Restore the Expense IndentationGiven pre-order amounts where each parent equals the sum of its immediate children, recover the lexicographically smallest 0-based indentation depth for every line.Medium7Dynamic programmingGreedy+2No attempts yet1s1024 MBJudgeable
Multi-Element Binary Search TreeGiven sorted search probabilities and level-dependent node capacities, find the minimum expected number of comparisons for a multi-element BST.Medium7Dynamic programmingTree+1No attempts yet1s1024 MBJudgeable
An Old Stone GameFor each of up to 10 general trees, compute the minimum number of stones needed so that starting from the bucket you can place a stone on the root by combining stones at fully occupied siblings.Medium7TreeGreedy+2No attempts yet1s128 MBJudgeable
Tree GameOn a tree, players alternately move a token to an unchosen neighbor from Manco's start vertex; find all start vertices where Manco wins with optimal play.Medium7TreeGame theory+2No attempts yet1s64 MBJudgeable
Coloured LeavesGiven an unrooted tree whose leaves have fixed colors, choose an internal vertex as root and place the fewest labels so each leaf's color matches its last labeled vertex.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Central TreeFor each weighted tree, find the vertex minimizing the sum of weighted distances to all other vertices and output that minimum sum.Medium7TreeDFS+2No attempts yet3s128 MBJudgeable
Lightning Energy ReportGiven a tree and many path updates that each add a value to every vertex on a path, report the final total at every vertex.Medium7TreePrefix sum+2No attempts yet1s256 MBJudgeable
Printed-Circuit BoardsGiven a series-parallel circuit described recursively, find the minimum number of connections that must be routed on the top side so every unit is reached from the top.Medium7TreeDynamic programming+2No attempts yet3s128 MBJudgeable
Binary Search Tree CodeGiven n and k, output the n-th preorder string among all BSTs built from the first k letters, listed in alphabetical order.Medium7TreeRecursion+2No attempts yet1s128 MBJudgeable
TreesGiven a sequence of leaf levels, decide whether it is a valid complete binary tree; if so, output the genealogical and bracket representations.Medium7TreeRecursion+2No attempts yet1s128 MBJudgeable
Mudstock BisPlace a festival at a settlement on a star of railway lines to minimize the weighted sum of distances from all members, and report the cost and location.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
MegalopolisCount, for each query at a given moment, the number of still-country roads on the path from village 1 to a target village as edges are removed one by one.Medium7TreeDFS+1No attempts yet1s128 MBJudgeable
StationPick a tree vertex as the hub so that the average number of hub-to-vertex paths needed to travel between unordered pairs of vertices is minimized.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Tree RotationsGiven a binary tree with distinct leaf labels, find the minimum number of inversions in the left-to-right leaf sequence reachable by swapping children at branchings.Medium7Divide and conquerDynamic programming+2No attempts yet1s128 MBJudgeable
Winter Snow PlowingOn a tree, each edge must be traversed at least d_i times by one continuous walk; find the minimum total traversal count.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Byton TreeGiven a tree in recursive notation, where each leaf has a time interval, find the minimum number of cuts (each cut picks every byton in the subtree at one moment) so that all intervals are covered.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
BarricadesOn a tree, for each size k find the minimum number of edges to cut so that some connected component has exactly k vertices and no edges leave it.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
TramsGiven a weighted tree, pair up the leaf nodes choosing disjoint simple paths to minimize or maximize the total length.Medium7TreeDynamic programming+1No attempts yet1s128 MBJudgeable
Two PostmenSplit the edges of a tree rooted at node 1 between two postmen starting at the root so the later finishing time is minimized.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Fiber Optic NetworkReserve bandwidth on tree paths for connect requests when capacity allows and release per-pair reservations on disconnect.Medium7Segment treeTree+1No attempts yet1s128 MBJudgeable
OfficialsIn a rooted tree of officials, match each denouncer with a distinct descendant subordinate to maximize the number of executed officials.Medium7GreedyTree+1No attempts yet1s512 MBJudgeable
TagA pursuer at K always steps toward an evader at J on a tree while the evader moves or waits to maximize the capture time.Medium7TreeGame theory+2No attempts yet5s128 MBJudgeable
TournamentCompute the chance that two named entrants meet in a knockout bracket with random seeding and even match odds.Medium7ProbabilityTree+1No attempts yet1s128 MBJudgeable
BillabongsConnect the weighted forest into one network with fixed-cost links so the longest travel time between any two ponds is as small as possible.Medium7TreeGreedy+1No attempts yet1s256 MBJudgeable
Up a TreeGiven three garbled preorder, inorder and postorder outputs from mixed-up recursive calls, list every call assignment and the smallest tree that fits each one.Medium7TreeBacktracking+2No attempts yet6s128 MBJudgeable
Slicing TreePlace the rotated rectangles under the slicing-tree constraints so the enclosing rectangle has minimum area.Medium7Dynamic programmingTreeNo attempts yet1s128 MBJudgeable
NetworkPlace the fewest additional servers on internal nodes so every leaf is within distance k of the nearest server.Medium7GreedyTreeNo attempts yet1s128 MBJudgeable
TreeDraw a crossing-free straight-line tree through n given points so each point has its required degree.Medium7GeometryTree+2No attempts yet1s128 MBJudgeable
ChonSuGiven the distances between consecutive leaves of an unknown full binary tree, compute the distance between two specified leaves.Medium7TreeDivide and conquer+1No attempts yet1s128 MBJudgeable
ParentsPick from 1 to K nodes of a valued tree with no parent-child pair so the sum of picked values is as large as possible.Medium7Dynamic programmingTreeNo attempts yet5s128 MBJudgeable
Electric NetworkGiven a connected network, compute the fewest new lines that keep every pair of facilities connected after any single line fails.Medium7DFSGraph+2No attempts yet1s128 MBJudgeable
Digital Content ProtectionGiven the hacked leaves of a complete binary key tree, print the identifiers of the smallest set of unexposed node keys covering every intact player.Medium7GreedyTree+1No attempts yet2s128 MBJudgeable
You Shall Not Pass!!Choose up to C coaching subtrees in a forest to maximize the number of teams covered by at least one chosen subtree.Medium7Dynamic programmingTreeNo attempts yet1s128 MBJudgeable
The Mayo EmpireEach new city joins the tree by one road with possible capital moves, and the task sums the farthest road count from the capital after every addition.Medium7TreeGreedyNo attempts yet1s128 MBJudgeable
ACM RevengeCompute the number of deaths before the first hunter reaches a treasure room in a binary tree with traps and toggling exits.Medium7TreeDynamic programming+1No attempts yet1s128 MBJudgeable
Delta QuadrantStarting anywhere on a weighted tree, find the shortest closed tour that visits all but k planets and returns to the start.Medium7Dynamic programmingTreeNo attempts yet5s128 MBJudgeable
Join two kingdomsTwo trees with up to 40000 nodes each are joined by one uniformly random cross edge, and you must output the expected diameter of the combined tree.Medium7TreeSorting+2No attempts yet1s128 MBJudgeable
Jingle BallsMove as few balls as possible so the two sides of every split differ by at most one ball, or report impossible.Medium7Dynamic programmingTreeNo attempts yet1s128 MBJudgeable
TraitorCover as many marked nodes of a forest as possible by assigning each a distinct neighboring watcher with no two marked nodes watching each other.Medium7Dynamic programmingTreeNo attempts yet1s128 MBJudgeable
Speed CamerasPlace the most cameras on the intersections of a tree so no simple route passes more than k cameras.Medium7GreedyTree+1No attempts yet1s128 MBJudgeable
Traveling SagaPrint the order in which an apple from vertex 1 visits every tree vertex by always moving to the farthest unvisited vertex, breaking ties by largest index.Medium7TreeSegment tree+1No attempts yet3s256 MBJudgeable
Code BreakingCount digit assignments to a rooted tree that place at least one of M forbidden 5-digit strings on its specified upward path, modulo 1234567.Medium7Dynamic programmingTree+1No attempts yet1s128 MBJudgeable
HotelsCount triplets of distinct towns in a tree whose three pairwise distances are all equal.Medium7TreeDynamic programming+1No attempts yet3s256 MBJudgeable
FarmCraftChoose a tour of the tree from the root that visits every house and returns, so the latest moment of arrival plus install time is as early as possible.Medium7GreedyTree+1No attempts yet3s256 MBJudgeable
Ant colonyAnt groups enter from every leaf, split evenly at each chamber with the rest eaten, and you count groups crossing one corridor with exactly k ants.Medium7TreeMath+2No attempts yet3s256 MBJudgeable
Safe Emergency Contact NetworkFor each road, report the cheapest total cost of a network connecting all villages without that road, or -1 when impossible.Medium7Minimum spanning treeTree+1No attempts yet1s64 MBJudgeable
Bridge RemovalStarting from any island, a crew that spends a bridge length to cross or remove it must delete every bridge of a tree in the shortest total time.Medium7Dynamic programmingTree+1No attempts yet1s256 MBJudgeable
The Club TripEach of n classmates rides only if one named classmate also rides; fill up to k bus seats with the largest group that respects every such condition.Medium7GraphDynamic programming+1No attempts yet1s256 MBJudgeable
Floating FormationPlace up to k spare boats on pieces linked pairwise by boats to minimize pieces lost in the cascade where a piece with fewer than two boats sinks.Medium7GraphTree+2No attempts yet1s256 MBJudgeable
Circle and MarbleEach move shifts one marble along an arrow to the next circle, and you decide if the first or second player wins under best play.Medium7Game theoryTree+1No attempts yet1s256 MBJudgeable
Stack Copying GameMaintain up to 300,000 persistent stack versions built by push, pop, or copy, and answer popped values and common-element counts for pairs of versions.Medium7TreeStackNo attempts yet1s64 MBJudgeable
Minimum spanning tree after deleting one edgeFor each edge, report the MST weight of the graph with that edge removed, or -1 when it disconnects.Medium7Minimum spanning treeTree+1No attempts yet3s256 MBJudgeable
The festival must go onPick M roads of a weighted tree so the longest path using only picked roads is as short as possible.Medium7Binary searchTree+1No attempts yet1s256 MBJudgeable
Bond TourEach parade route is the tree path between two towns, and you report the best contiguous stretch of road weights on it, or zero.Medium7Segment treeTreeNo attempts yet5s256 MBJudgeable
Tree of Almost Clean MoneyEach operation adds generated values to up to 1000 vertices and asks for the sum on the path between two vertices.Medium7TreeSegment treeNo attempts yet4s256 MBJudgeable
Slant DrillingChoose a ground point over nested contour polygons so the straight-line distance from the surface to the pocket at the origin is shortest.Medium7GeometryTree+1No attempts yet1s256 MBJudgeable
AYBABTUYou cut k tree edges so each of the resulting k+1 regions holds a base and the total cut cost is smallest.Medium7Dynamic programmingTreeNo attempts yet10s512 MBJudgeable
TerroristsGiven a connected graph with at most 50 extra edges past a tree, answer the shortest distance for each query pair.Medium7Shortest pathTreeNo attempts yet5s256 MBJudgeable
Mario and the Evil ToadPick K distinct non-root nodes of a weighted tree and order them to maximize the round trip from the root through them in order.Medium7Dynamic programmingTree+1No attempts yet3s256 MBJudgeable
BiochipsPick exactly M nodes from a rooted tree with given values so no picked node is an ancestor of another and the sum is maximal.Medium7Dynamic programmingTreeNo attempts yet2s512 MBJudgeable
Yonsei University Point GamePlayers paint tree nodes blue and queries ask for the sum of weighted distances from a node to all painted nodes.Medium7Divide and conquerTree+1No attempts yet5s128 MBJudgeable
Costly Binary Search (Small)Find the comparison order that minimizes the worst-case total cost of locating the insertion position when each array slot has its own comparison cost.Medium7Dynamic programmingTree+1No attempts yet5s512 MBJudgeable
Symmetric Trees (Large)Decide whether a color-painted tree can be drawn in the plane with a vertical line of symmetry.Medium7TreeRecursion+2No attempts yet5s512 MBJudgeable
Full Binary Tree (Large)Delete as few vertices as possible from a given tree so the survivors form a full binary tree with a freely chosen root.Medium7Dynamic programmingTree+1No attempts yet5s512 MBJudgeable
World Cup 2010 (Large)Pick the cheapest tickets in a knockout bracket so each team misses at most M[i] of the matches it plays, no matter who wins.Medium7Dynamic programmingTreeNo attempts yet5s512 MBJudgeable
Rainbow TreesCount rainbow edge colorings of a tree where any two adjacent edges differ and any three consecutive edges all differ, modulo 1e9+9.Medium7TreeGreedy+2No attempts yet5s512 MBJudgeable
Mixing Bowls (Large)Given a recipe where each mixture's ingredients are other mixtures, find the minimum number of bowls needed to prepare it.Medium7TreeDFS+2No attempts yet5s512 MBJudgeable
Busiest railway segment (large)Given a tree and Q paths, count how many paths use each edge and report the edge with the maximum count, breaking ties by lexicographic order of endpoints.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
TorrentTwo computers start with a file in a tree; each minute, adjacent computers can copy in parallel subject to one copy per computer. Find the minimum minutes until all nodes have the file.Medium7TreeBFS+2No attempts yet2s512 MBJudgeable
Tree EditCut one weighted edge of a tree and reattach it elsewhere with the same weight; find the maximum possible diameter.Medium7TreeDFS+1No attempts yet2s512 MBJudgeable
Scrooge Minho 2Given a tree with N cities, place the fewest police stations so that every city and every road is covered, where a station covers its city, its neighbors, and all incident roads.Medium7TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Hongjun and the Tree 2Count the ways to cut edges of a tree so every remaining component has exactly one black vertex, modulo 1e9+7.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
Holiday RoadsOn a tree, each of M families picks one of the other N-1 cities uniformly and independently; find the expected number of roads used by every family.Medium7TreeProbability+1No attempts yet2s512 MBJudgeable