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 results839 problems
| Title | Level | Topics | Solved | Time limit | Memory limit | Judge |
|---|---|---|---|---|---|---|
| Pesky HeroesGiven a tree-like cave structure with orc traversal rules based on left/right turns and one allowed right-turn override, find the minimum number of gateways needed to reach all trap-free dead ends. | Hard8 | TreeSimulation+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Cosmic StationGiven all pairwise distances between leaves of a tree, determine the number of internal (branching) nodes. | Hard8 | TreeGraph+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Ninja AssignmentChoose a manager and up to budget many ninjas from the manager's subtree, possibly passing through unassigned ninjas, to maximize assigned count times the manager's leadership. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 256 MB | Judgeable |
| PatrolBuild K (1 or 2) unit-length shortcuts in a tree so that the shortest closed walk from village 1 covering every edge exactly as required is minimized. | Hard8 | TreeDynamic programming+2 | No attempts yet | 1s | 64 MB | Judgeable |
| Paper RouteWith N+1 nodes and exactly N roads, find the cheapest closed walk from node 0 covering all addresses, then add the campus travel cost from wherever you end. | Hard8 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Rotate to RootGiven a binary tree, compute the height of the tree after each node is rotated to the root one at a time. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| TreequivalenceGiven two textual tree notations, decide whether they describe the same unrooted planar drawing, allowing any root and cyclic order around each vertex. | Hard8 | TreeHash map+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Split WindowsGiven a preorder traversal of a split tree, draw the minimum-sized grid whose boundaries match the layout, applying proportional rounding at each split. | Hard8 | TreeRecursion+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Dr. Podboq, or: How We Became AsymmetricRead a binary tree of cells, define each cell's left-right similarity by shared subtree shapes up to child swaps, then reorder children by asymmetry and print the normalized tree. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Flight PlanningGiven a tree, delete one edge and add one edge so the result is a tree with the smallest possible diameter. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| FishGiven fish lengths and gem kinds, count how many distinct gem-count combinations a single fish can ever hold, modulo M, where a fish can eat another only if at least twice as long. | Hard8 | Dynamic programmingSorting+2 | No attempts yet | 3s | 128 MB | Judgeable |
| Sabotaging the Marathon TrainingGiven a spanning tree of paved edges plus weighted unpaved edges, delete cheap unpaved edges so that no even-length simple cycle remains. | Hard8 | GraphDynamic programming+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Tree PathGiven a directed tree, find the minimum number of reversed-edge paths to add so that every node can reach every other node. | Hard8 | TreeGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Joining CouplesEach city has one directed outbound flight, forming a functional graph; for each query find the minimum combined distance from two starting cities to any common reachable city, or -1. | Hard8 | GraphTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Power GenerationBuild the tree formed by attaching each new plant to the nearest older one, then split it into the most connected subtrees each having total capacity at least C. | Hard8 | TreeDynamic programming+2 | No attempts yet | 3s | 128 MB | Judgeable |
| Optical FiberGiven a tree of cities, each with up to 50 candidate router sites, pick one site per city to minimize the sum of Euclidean edge lengths. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| The Crayfish ScrivenerProcess type and undo commands, including nested undos, and answer queries for the character at a given position. | Hard8 | StackTree+2 | No attempts yet | 2s | 512 MB | Judgeable |
| RaceGiven a weighted tree, find a path of total length exactly K that uses the fewest edges, or report -1 if none exists. | Hard8 | TreeDivide and conquer+2 | No attempts yet | 3s | 256 MB | Judgeable |
| Balanced TreesGiven a tree whose nodes are labeled with parentheses, find the maximum nesting depth over all paths that spell a balanced parenthesis string. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Farm ManagementA tree of N farms gets path updates that add 1 to every edge on a path, plus path queries that sum edge values on a path; process M operations online. | Hard8 | TreeSegment tree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Cow TelephonesGiven a tree with cows at its leaves and vertex capacity K plus unit edge capacity, find the maximum number of disjoint leaf-to-leaf conversation paths. | Hard8 | TreeDynamic programming+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Rocks and TreesRocks sit on the non-root nodes of a rooted tree; players alternately push up to L rocks from a node to its parent, and after each point update you decide if the first player wins. | Hard8 | Game theoryTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Pink FloydGiven the all-pairs shortest-distance matrix of a weighted tree, reconstruct any tree that produces these distances and print its adjacency list. | Hard8 | TreeGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Rectangular PaintingGiven a nesting tree of rectangles and photo leaf sizes, orient each sibling group horizontally or vertically to minimize the root rectangle area. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Minimum-Cost Prefix-Free LanguageGiven n and d character costs, find the minimum total cost of a prefix-free set of exactly n words; multiple test cases end with 0 0. | Hard8 | Dynamic programmingGreedy+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Quelling BladeGiven a tree of weapon prerequisites with costs and benefits, find a buying order that reaches the root in minimum time while maximizing the sum over time of owned benefit. | Hard8 | GreedyDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Ball MachineSimulate a ball machine on a rooted tree: dropping balls follows a fixed priority path, and removing a ball makes balls above roll down; report resting node or number of moves. | Hard8 | TreeSimulation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Tree InsertionsCount how many permutations of a given sequence build the same binary search tree; values may repeat and answers need big integers. | Hard8 | TreeCombinatorics+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Failing RoadsGiven an expression tree of merge and complement operations, compute the maximum independent set of the resulting graph. | Hard8 | TreeDynamic programming+2 | No attempts yet | 1s | 128 MB | Judgeable |
| BoatherdsGiven a weighted tree and up to 100 queries, decide for each target value whether some pair of vertices has a path cost exactly equal to it. | Hard8 | Divide and conquerTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Nutrient TreeGiven a binary tree whose leaves produce nutrients and whose edges have capacity (1+w)^2 after spending w agents, distribute X agents over edges and leaves to maximize the flow reaching the root. | Hard8 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Word CountingGiven a rooted tree whose edges carry letter strings, count distinct occurrences of a query word along all paths from the root to the leaves, identifying each occurrence by its start and end position. | Hard8 | String matchingTrie+2 | No attempts yet | 1s | 128 MB | Judgeable |
| TollA billionaire sets tolls on K new roads of his choosing so that the minimum spanning tree routing all traffic to town 1 maximizes his revenue, where K is at most 20. | Hard8 | Minimum spanning treeGreedy+2 | No attempts yet | 3s | 128 MB | Judgeable |
| UnterA connected graph with N houses and exactly N edges (one cycle) must answer up to 1e6 shortest distance queries. | Hard8 | GraphDFS+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| ThievesGiven a tree with K robbed cities, block some cities at cost a_i so that the reachable set of cities from the robbed nodes through unblocked cities is minimized in total cost (blocking plus M per searched city). | Hard8 | TreeDynamic programming+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| Fixing CodesGiven a prefix-free code and a new binary string, find the minimum total number of bits to append so the whole multiset becomes prefix-free again. | Hard8 | GreedyTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Tree SimilarityGiven two ordered rooted trees, find the minimum number of node relabel, delete, and insert operations to turn the first tree into the second. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 3s | 128 MB | Judgeable |
| City DrivingIn a connected graph with N nodes and N edges, answer many shortest-path queries between pairs of nodes. | Hard8 | TreeGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Highway ConstructionChoose a path in a weighted tree so that the maximum distance from any node to the path is minimized, and report that distance. | Hard8 | TreeBinary search+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Worst LocationsGiven a perfect binary tree and two distance-from-leaf descriptions, decide whether some pair of matching vertices sits farther than Z apart. | Hard8 | TreeGeometry+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Counting BSTCount insertion sequences of distinct values from 1..M that build a BST with the same shape as a given sequence, modulo 1000003. | Hard8 | CombinatoricsTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Counting HeapsCount the number of ways to label a rooted tree with 1..n so each node is smaller than its parent, modulo a possibly composite m. | Hard8 | CombinatoricsTree+2 | No attempts yet | 5s | 128 MB | Judgeable |
| CaveGiven a tree of n nodes, find every k such that the tree splits into k connected parts of equal size. | Hard8 | TreeDFS+2 | No attempts yet | 3s | 256 MB | Judgeable |
| Ternary TreesLabel the leaves of a complete ternary tree so that, given a fixed query order, the leaf values stay hidden until every leaf is asked. | Hard8 | TreeRecursion+2 | No attempts yet | 1s | 128 MB | Judgeable |
| FirefighterOn a graph with max degree 3, fire spreads one step per hour while one house can be protected each hour; maximize houses kept safe. | Hard8 | GraphTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Fruit ChickenA tree has shops at one end and houses at the other, separated by a single bridge edge; assign each open shop a distinct house minimizing the time until all couriers arrive, with no two couriers sharing a road at once. | Hard8 | TreeBinary search+2 | No attempts yet | 3s | 128 MB | Judgeable |
| IslandGiven all pairwise shortest tolls among the n seaside triangles, recover the adjacency structure and edge weights of the underlying border tree. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| PolygonsA convex polygon is triangulated, one triangle is black; players alternately cut off an ear triangle, and whoever removes the black triangle wins. Decide if the first player wins. | Hard8 | Game theoryTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| The Lightest LanguageGiven n, k, and letter weights, find the minimum total weight of a prefixless set of exactly n words over k letters. | Hard8 | TreeGreedy+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Step Traversing a TreeGiven a tree on n vertices, find the smallest c such that the vertices can be visited in some order where each consecutive pair is at distance at most c. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| SubwayGiven a tree with n stations, choose l non-branching paths (routes) to cover as many distinct vertices as possible. | Hard8 | TreeDynamic programming+1 | No attempts yet | 3s | 128 MB | Judgeable |
| Fire Extinguisher InstallationPlace extinguishers on tree rooms, each covering at most S rooms within distance K, so every room is covered; minimize the count. | Hard8 | TreeGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| DynamiteLight the fuses in exactly m chambers of a tree so that every charge-detonation is covered as early as possible, and report the last detonation time. | Hard8 | TreeBinary search+2 | No attempts yet | 2s | 128 MB | Judgeable |
| InspectionFor each root of a tree, find the minimum time for a tour that inspects every node and returns to the root each time, with no two consecutive trips using the same first edge. | Hard8 | TreeDFS+2 | No attempts yet | 5s | 128 MB | Judgeable |
| SalariesGiven a rooted tree with salaries a permutation of 1 to n increasing toward the root and some values revealed, print each value forced by the revealed ones or 0 otherwise. | Hard8 | TreeGreedy+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Triumphal ArchGiven a tree rooted at town 1, find the minimum number of crews so that each town gets its arch built before the king's first arrival, where the king's walk is unknown. | Hard8 | TreeGreedy+2 | No attempts yet | 1s | 128 MB | Judgeable |
| FuelFind the maximum number of distinct vertices of a tree that can be visited by a walk of length at most m edges. | Hard8 | TreeDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Number of Tree AutomorphismsCount the automorphisms of a tree modulo 1e9+7. | Hard8 | TreeDFS+2 | No attempts yet | 5s | 128 MB | Judgeable |
| FirmProcess hires and queries on a growing rooted tree, counting employees at exact depth offset k below a given node at query time. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| DivisorsGiven n and an expression built from divisors of n with gcd and lcm, decide whether the expression's value is the same for every assignment of variables. | Hard8 | Number theoryTree+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Termites 2Given a tree with its edges ordered, two players alternately remove an uneaten endpoint of the next edge; report the round the loser is forced and loses, or -1 for a draw. | Hard8 | Game theoryTree+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Enumeration of Road Network PlansCount the isomorphism classes of trees on n vertices whose diameter equals d, modulo a prime p. | Hard8 | CombinatoricsTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| WormsOn a tree, worms each move every hour to an adjacent house; decide whether they can all meet and find the minimum number of hours. | Hard8 | TreeGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Binary Tree Lexicographic NumberGiven binary trees with ordered left and right children, find each tree's rank in height-first lexicographic order modulo 1000000000. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Untamed TreeThe task is to output for each leaf label the compressed subtree of its leaves and branching ancestors in preorder. | Hard8 | TreeSorting+2 | No attempts yet | 1s | 128 MB | Judgeable |
| The Company ChoirGiven a rooted tree where each node has a pitch and a distinct ability score, answer queries that ask for the k highest-ability subordinates of a node whose pitch lies in a range [a,b]. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| RacesGiven a tree and a set of allowed endpoints, find the maximum number of vertex-disjoint paths whose endpoints both lie in the allowed set. | Hard8 | TreeDynamic programming+2 | No attempts yet | 1s | 128 MB | Judgeable |
| SpidersGiven two planar triangulations built by repeatedly attaching a new vertex to an outer edge, decide whether they are isomorphic as graphs. | Hard8 | GraphTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| House of CardsMarcel removes at most k cards in whole leaning pairs, clearing cards above before the cards they rest on, to maximize the recovered sum. | Hard8 | Dynamic programmingTree | No attempts yet | 1s | 512 MB | Judgeable |
| DrzewaFor each node of a labeled rooted tree, find the leaf below it whose downward label string is lexicographically largest, breaking ties by smaller leaf number. | Hard8 | TreeGreedy+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Heavy BlocksTopple n distinct-weight blocks with the fewest pushes when each push fells lighter neighbors in one direction until a heavier block or gap. | Hard8 | Dynamic programmingStack+2 | No attempts yet | 1s | 128 MB | Judgeable |
| The ChampionshipPair as many employees as possible so each team holds two people with neither managing the other. | Hard8 | GreedyTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Contour MapGiven up to 20000 non-crossing convex orthogonal polygons, compute the maximum nesting depth where the outermost level is 1. | Hard8 | GeometrySorting+2 | No attempts yet | 3s | 128 MB | Judgeable |
| Tree LabelingThe program counts labelings of a tree with up to 1000 vertices that preserve each label's neighbor label set. | Hard8 | TreeCombinatorics+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Series-Parallel Parking LotPlace as many extra cars as possible on empty spaces of the encoded lot so every car still reaches the exit through empty spaces. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 2s | 256 MB | Judgeable |
| Disjoint water supplyCount the pairs of cities with paths from city 1 that meet only at city 1 in a pipe network ordered by decreasing altitude. | Hard8 | GraphTopological sort+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Inverting HuffmanGiven code lengths that some Huffman run can produce, find the smallest total character count that allows those lengths. | Hard8 | GreedyTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Moves on an Infinite Binary TreeStarting from the node reached by S, count the distinct nodes reachable by following any subsequence of T on an infinite binary tree. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Hidden TreeFind the longest subsequence that forms the leaves of a binary tree where each internal node has equal left and right sums. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 5s | 128 MB | Judgeable |
| Safari ParkTriangles are inserted one at a time and each query asks which earlier triangle strictly contains a point, reporting -1 on a boundary and 0 outside. | Hard8 | GeometryTree | No attempts yet | 5s | 128 MB | Judgeable |
| PolarizationOrient every edge of the given tree and report the smallest and largest possible numbers of town pairs connected by a directed path. | Hard8 | TreeDynamic programming+1 | No attempts yet | 3s | 512 MB | Judgeable |
| Beads and WiresYou choose append and insert orders that build the given weighted tree to maximize the total length of insert-created edges. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| SupercomputerGiven a rooted tree of unit-time tasks and many processor counts, compute the fastest finishing time for each count. | Hard8 | TreePrefix sum+2 | No attempts yet | 2s | 256 MB | Judgeable |
| Persuading the AdvisersTwo rivals take turns claiming undecided experts for opposite sides, and the first asks whether he can force the majority-vote tree to favor him. | Hard8 | Game theoryTree+2 | No attempts yet | 1s | 256 MB | Judgeable |
| Recovering the PopulationsGiven a tree and the distance-weighted sums at each node, recover the node weights that produce them. | Hard8 | TreeDFS+1 | No attempts yet | 4s | 256 MB | Judgeable |
| CheatsCount the completion orders of a tree of prerequisites when up to k parent edges can be skipped to grandparents, with no two skipped edges adjacent. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 10s | 256 MB | Judgeable |
| Lengthy Traveling SalesmanArrange every vertex of a tree into a tour that maximizes the total walked distance and return the lexicographically smallest among the longest tours. | Hard8 | TreeGreedy | No attempts yet | 1s | 256 MB | Judgeable |
| Road RepairFind a tree path with total cost at most C that maximizes total benefit. | Hard8 | TreeDivide and conquer+1 | No attempts yet | 1s | 256 MB | Judgeable |
| String TransformationFind the fewest adjacent swaps turning one balanced a/b string into another with every intermediate string balanced, or output -1 if impossible. | Hard8 | TreeStack+1 | No attempts yet | 1s | 256 MB | Judgeable |
| ParadesPick the most parade routes between pairs of junctions in a tree so no street is shared by two parades. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 3s | 256 MB | Judgeable |
| Volunteer CampStarting from each house in a weighted tree, find the shortest truck route that visits K marked houses without driving back. | Hard8 | TreeDynamic programming+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Transmutation CirclesFind the activation order of nested circles that maximizes total energy from element flips in already active circles. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 10s | 256 MB | Judgeable |
| Pangaea 2Starting from a given tree, each added road updates the minimum total length that keeps all cities connected, and each test case outputs the XOR of the answers. | Hard8 | Minimum spanning treeTree | No attempts yet | 20s | 256 MB | Judgeable |
| Which intersections did I pass?Given a connected undirected graph, each query asks how many vertices lie on some walk from a to b that never revisits the endpoints in the middle. | Hard8 | GraphDFS+1 | No attempts yet | 2s | 256 MB | Judgeable |
| Reducing Network DiameterPay per unit of reduction on tree edge weights so the longest path between any two nodes is at most D at minimum total cost. | Hard8 | GreedyTree+2 | No attempts yet | 2s | 256 MB | Judgeable |
| Who Do You Think You Are?Read a family tree and answer queries naming the relationship of name1 to name2, including blood, cousin, and in-law terms. | Hard8 | GraphTree+2 | No attempts yet | 2s | 256 MB | Judgeable |
| Tree of PainDecide for each small pattern tree whether it embeds into the organization tree with matching labels and ancestry preserved both ways. | Hard8 | TreeDynamic programming+2 | No attempts yet | 1s | 256 MB | Judgeable |
| Party joke setsCount distinct joke-type sets from root-connected guest groups with unique values where each subtree below a guest forms consecutive numbers. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 1s | 32 MB | Judgeable |
| Juice JunctionsAdd up the maximum unit-capacity flow between every pair of junctions in a graph where each junction joins at most three pipes. | Hard8 | GraphTree+2 | No attempts yet | 7s | 512 MB | Judgeable |
| Tree AllocationPartition the nodes into blocks of at most B to minimize the worst root-to-leaf block count, for every choice of root. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 10s | 64 MB | Judgeable |