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 |
|---|---|---|---|---|---|---|
| Balanced PathsCount ordered node pairs whose labels along the tree path form a balanced parenthesis string. | Hard8 | Divide and conquerHash map+2 | No attempts yet | 3s | 256 MB | Judgeable |
| Content DeliveryPick an item and destination for each of m deliveries on a weighted tree with path caching to maximize total size times travel distance. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 5s | 256 MB | Judgeable |
| Post Office InvestigationGiven a directed delivery network from office 1, each query asks for the cheapest office that lies on every route to all listed complaint offices. | Hard8 | GraphTree | No attempts yet | 3s | 256 MB | Judgeable |
| Sunlight on a TreeReport all nodes on the tree path from u to v whose dot product with the query direction is minimal. | Hard8 | TreeSegment tree+1 | No attempts yet | 5s | 256 MB | Judgeable |
| Special graphEdge deletions hit a functional graph while queries ask for the directed distance from a to b along the single outgoing walk. | Hard8 | GraphTree+1 | No attempts yet | 1s | 64 MB | Judgeable |
| Longest Shortest Paths at ShymbulakCount every shortest path between all vertex pairs at the maximum distance in a connected graph with N vertices and N equal edges. | Hard8 | GraphBFS+2 | No attempts yet | 2s | 256 MB | Judgeable |
| RoadsEdges of a weighted tree are deleted in the given order, and after each deletion you report the diameters of the two resulting components in increasing order. | Hard8 | Union-findTree | No attempts yet | 5s | 512 MB | Judgeable |
| CabinsFind the K-th smallest travel distance among all pairs of cabins placed on a weighted tree of river regions. | Hard8 | Binary searchDivide and conquer+1 | No attempts yet | 6s | 64 MB | Judgeable |
| K-th smallest weight on a tree pathAnswer each query with the K-th smallest vertex weight on the path between two vertices in a tree. | Hard8 | Segment treeTree+1 | No attempts yet | 1.5s | 512 MB | Judgeable |
| Fairland (Large)Keep the largest rooted connected subtree containing the CEO so all kept salaries fit within a range of width D. | Hard8 | TreeSliding window+2 | No attempts yet | 10s | 512 MB | Judgeable |
| Willow (Large)Two players pick starts on a coin tree and alternately take city coins while each used road closes for both, and the first player maximizes the score gap. | Hard8 | Game theoryTree+1 | No attempts yet | 120s | 512 MB | Judgeable |
| PoklonGiven a tree of scales, add positive real weights so every scale balances with minimum total added mass, then print the final total mass in binary. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 256 MB | Judgeable |
| FireworksGiven a rooted tree whose leaves are explosives and whose edges have lengths, find the minimum total change of edge lengths so all leaves ignite at the same time. | Hard8 | TreeDynamic programming+1 | No attempts yet | 2s | 512 MB | Judgeable |
| BossesBuild a rooted tree on n employees where each node's parent is one of its accepted bosses, then assign minimum positive salaries with every boss exceeding the sum of children. | Hard8 | TreeDynamic programming+2 | No attempts yet | 1.5s | 256 MB | Judgeable |
| Longest RiversGiven a river network tree and source names, find for each name the best rank it can achieve over all valid downstream naming choices. | Hard8 | TreePrefix sum+2 | No attempts yet | 10s | 512 MB | Judgeable |
| Bridge testingGiven a weighted tree and two timed walkers on their respective paths, decide for each query whether both occupy some bridge simultaneously over a positive-length interval. | Hard8 | TreeDynamic programming+2 | No attempts yet | 4s | 256 MB | Judgeable |
| Similar SubwaysGiven two trees with up to 50 nodes each, find the largest k such that some connected k-node subtree of the first is isomorphic to some connected k-node subtree of the second. | Hard8 | TreeDynamic programming+2 | No attempts yet | 3s | 512 MB | Judgeable |
| InvestigationGiven a tree and a thief hidden at one node, find the minimum worst-case number of queries to locate him in an optimal search strategy. | Hard8 | TreeDynamic programming+1 | No attempts yet | 2s | 1024 MB | Judgeable |
| NewspapersGiven a weighted tree, find the maximum average edge weight over all simple paths that contain at least k edges, printed to eight decimals. | Hard8 | Binary searchDynamic programming+2 | No attempts yet | 4s | 1024 MB | Judgeable |
| Sum of ScoresFind a non-empty vertex subset connected in both given trees whose score sum is maximized, with vertex counts up to 50. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Hongjun and the Possible SetsCount the nonempty connected vertex subsets of a weighted tree whose maximum minus minimum weight is at most d. | Hard8 | TreeDFS+2 | No attempts yet | 3s | 512 MB | Judgeable |
| Hongjun and the TreeProcess subtree updates that add a distance-dependent value to each vertex, answering point-weight queries modulo 1e9+7. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Easily Happy TreeDelete the fewest leaves from a rooted tree so that no remaining vertex has a descendant farther away than that descendant's own limit a_u. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| TreeMaintain a rooted tree under vertex deletions (children reparent to grandparent) and answer distance queries between two live vertices. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| BarbariansA tree's edges are deleted one by one, each deletion multiplies each vertex's anger by (reachable before) - (reachable after) + 1, and after each deletion the total anger is printed modulo 1e9+7. | Hard8 | TreeUnion-find+2 | No attempts yet | 4s | 512 MB | Judgeable |
| Alternative Bracket NotationConvert a balanced bracket string into the shortest alternative notation, where each pair's header gives absolute start and end indices of its contents. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 10s | 512 MB | Judgeable |
| Programming TeamChoose exactly k candidates from a tree where each pick needs its recommender picked, maximizing total productivity divided by total salary; print the ratio to three decimals. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 3s | 512 MB | Judgeable |
| TouristsGiven a tree on n nodes, sum the number of nodes on the path from x to y over all pairs where y is a larger multiple of x. | Hard8 | TreeMath+2 | No attempts yet | 5s | 512 MB | Judgeable |
| Optimal TournamentPlace N contestants with given strengths at the leaves of a knockout bracket of height at most K so that the total strength difference over all matches is minimized. | Hard8 | Dynamic programmingSorting+2 | No attempts yet | 5s | 512 MB | Judgeable |
| Quarantine StationsPlace K quarantine barriers on the edges of a weighted tree so that the largest connected component's total population is minimized. | Hard8 | TreeBinary search+1 | No attempts yet | 3s | 256 MB | Judgeable |
| TreeAfter each query asks whether two vertices are still connected, the tree may lose one edge based on the answer, so connectivity must be tracked under online deletions. | Hard8 | TreeUnion-find+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Cartesian TreeCount permutations of 1..N whose Cartesian tree has total child-position gap score at most S, modulo a prime. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 5s | 512 MB | Judgeable |
| Two TreesPick a vertex subset connected in both of two trees to maximize the total score, with the empty set allowed. | Hard8 | TreeDFS+1 | No attempts yet | 2s | 512 MB | Judgeable |
| InterceptionPlace the fewest listening devices on the edges of a street-wide phone-line graph so that every given call route is covered. | Hard8 | GraphGreedy+2 | No attempts yet | 8s | 512 MB | Judgeable |
| Counting Similar TreesGroup labeled trees that are isomorphic under a bijection preserving edge label differences, and report each group size. | Hard8 | TreeHash map+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Placing Medals on a Binary TreeGiven medals with depths in a pile, decide greedily and incrementally which can be placed on a perfect binary tree so that no placed node is an ancestor of another. | Hard8 | GreedyTree+1 | No attempts yet | 4s | 512 MB | Judgeable |
| Blue vertex distance sums on a treeProcess paint and distance-sum queries on a weighted tree, reporting for each query 2 the total distance from x to all blue vertices. | Hard8 | TreePrefix sum+2 | No attempts yet | 5s | 512 MB | Judgeable |
| Farthest White Pair in a TreeMaintain a tree whose vertices flip between white and black, and after each flip report the largest distance between two white vertices, where edge lengths may be negative. | Hard8 | TreeDivide and conquer+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Vertices connected by the same colorProcess color flip and reachability queries on a tree where two vertices are connected if every vertex on their path has the same color. | Hard8 | TreeUnion-find+2 | No attempts yet | 2s | 512 MB | Judgeable |
| K-th smallest weight on a tree pathFor each query, print the k-th smallest vertex weight on the unique tree path between two vertices. | Hard8 | TreeBinary search+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Weighted sum queries on a mutable sequenceMaintain a sequence under insert, delete, and replace, and answer weighted-sum range queries where each element is multiplied by its offset to the power k (k up to 10). | Hard8 | TreeBinary search+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Memory CellBuild the expression tree, find the largest pair of disjoint identical subtrees, and print the loser's postfix in lexicographic order. | Hard8 | StackTree+2 | No attempts yet | 1s | 512 MB | Judgeable |
| VirusGiven a binary tree, find the minimum number of nodes that end up infected when one node may be protected each round. | Hard8 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| BurzaGiven a tree and a blind pre-committed node-marking order, decide whether the coin can be forced to move fewer than K times regardless of the adversary's play. | Hard8 | Game theoryTree+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Calculating TaxesOn a tree where each house picks a divisor of its income, maximize the total sum of chosen values so that every pair of adjacent houses picks coprime values. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 8s | 512 MB | Judgeable |
| ACM TaxFor each query path in a weighted tree, output the median edge length, rounded to one decimal. | Hard8 | TreeBinary search+2 | No attempts yet | 5s | 512 MB | Judgeable |
| Dictionary GameWords are destroyed by prefix cuts; after each insertion into the dictionary, report which player wins the impartial game under optimal play. | Hard8 | Game theoryTrie+2 | No attempts yet | 5s | 512 MB | Judgeable |
| Sky TaxOn a tree with a moving capital, each vertex answers for all vertices whose path to the capital passes through it; move the capital or query a vertex's count. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| BitstockGiven share prices, income rates, and a support forest where each owned share can subsidize its children at half price, find the minimum time until income reaches P per second. | Hard8 | GreedyTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Beautiful PathsOn a tree with capitals 1 and 2, sum over all pairs of cities of the minimum distance-to-nearest-capital along their path. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Scout GatheringsOn a tree, support adding a member at a city and querying the sum of weighted distances from all members to the current gathering city, which moves along edges. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Company Culture 4On a rooted tree, praise spreads downward from an employee to all descendants or upward to all ancestors, the direction flips over time, and queries ask for an employee's accumulated praise. | Hard8 | TreePrefix sum+2 | No attempts yet | 2s | 512 MB | Judgeable |
| WellsOn a tree where placing wells at a vertex counts for it and its direct neighbors, find the minimum number of wells so every village's demand is met. | Hard8 | TreeDynamic programming+2 | No attempts yet | 2s | 256 MB | Judgeable |
| Ski ResortFor each query, count the size-k sets of areas such that every favorite area has exactly one stocked area lying on every path from the top, and all chosen areas lie on paths to favorite areas. | Hard8 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Yeongseon takes the baitOn a tree, count alternating left/right paths from a fixed start where each vertex is used once; report the maximum over all starting vertices. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| City AttractionsOn a weighted tree, Gigel repeatedly jumps from his current city to the city maximizing a_y - dist(x, y), breaking ties by smallest index, and we must report his position after K days. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 64 MB | Judgeable |
| Tree path decompositionCount the ways to partition all nodes of an unrooted tree into vertex-disjoint paths, where each path's node sum is nonnegative, modulo 1e9+7. | Hard8 | TreeDynamic programming+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Who made the Christmas soundRoot the tree at socket 1 and count colorings with R, G, B bulbs, respecting the green and blue adjacency rules, whose total cost is divisible by K. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Broadcast StationsGiven a tree, assign non-negative integer powers to vertices so every zero-power vertex lies within reach of some positive-power vertex, minimizing the total power. Report that minimum sum. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 0.5s | 512 MB | Judgeable |
| Booming BusinessCount ordered rooted trees with exactly w nodes and height exactly h, modulo 1e9+7, where children of each node are an ordered sequence. | Hard8 | Dynamic programmingCombinatorics+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Royal TaxGiven a tree of cities, each with tax gold and a carriage of capacity C, find the minimum total distance to collect all gold into the capital vault. | Hard8 | TreeDynamic programming+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| Rainbow RoadsGiven a tree whose edges are colored, find every node v such that all simple paths starting at v have no two consecutive edges of the same color. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Hidden SupervisorsGiven a partial parent array, fill in the missing supervisors to complete a rooted tree and maximize the number of disjoint parent-child pairs. | Hard8 | TreeDynamic programming+2 | No attempts yet | 3s | 512 MB | Judgeable |
| Balloon WarehouseSimulate repeated insertions into an infinite balloon line, then report the colors at positions l to r-1 after all instructions. | Hard8 | TreeDFS+2 | No attempts yet | 7s | 512 MB | Judgeable |
| Infinite TreesGiven two possibly infinite trees defined by node-to-children mappings, decide whether their roots have the same ordered structure, where recursive nodes make the unfolding infinite and require comparing regular trees. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| CounterspellsAfter each of n leaf insertions into a rooted tree, find the minimum number of vertex recolorings needed to restore the unique well coloring. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| Corporate life after a hostile takeoverGiven two rooted trees on the same n employees, count for each employee how many others are descendants in both trees. | Hard8 | TreeDFS+2 | No attempts yet | 0.5s | 1024 MB | Judgeable |
| MousetrapOn a tree, Dumbo blocks or cleans edges while an edge-averse mouse moves; find the minimum moves to force it into the trap. | Hard8 | TreeDFS+2 | No attempts yet | 5s | 512 MB | Judgeable |
| ChaseJerry walks a simple path in a tree, dropping up to v breadcrumbs that zero out neighbor pigeon counts; maximize the pigeons Tom later meets minus the pigeons Jerry met. | Hard8 | TreeDynamic programming+1 | No attempts yet | 4s | 512 MB | Judgeable |
| Cumulative CodeFor the complete binary tree of depth k, answer q queries each summing m elements of its Prüfer code at positions a, a+d, ..., a+(m-1)d. | Hard8 | MathTree+2 | No attempts yet | 7s | 512 MB | Judgeable |
| Embedding EnumerationCount the ways to place a labeled tree's nodes into a 2 by n grid so node 1 sits at the top-left, edges touch, and no cell repeats, modulo 1e9+7. | Hard8 | TreeDFS+2 | No attempts yet | 4s | 512 MB | Judgeable |
| Hyunsoo CityGiven a connected cactus graph with toggleable edges, answer connectivity queries under edge updates, where each edge lies on at most one cycle. | Hard8 | GraphDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Directing the TreeCount the orientations of a tree's edges such that every given vertex pair has a directed path one way or the other, modulo 1e9+7. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 256 MB | Judgeable |
| Getting Back HomeOn a tree with home at node 1 and office at node n, find the smallest flashlight range d so that a random walk governed by visibility rules always reaches home within 10^9 steps. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| BureaucracySimulate repeatedly sending a task down the smallest-numbered child on each root-to-leaf path, paying 1,2,3,... coins up the chain, and deleting the leaf. | Hard8 | TreeDFS+2 | No attempts yet | 1s | 64 MB | Judgeable |
| Christmas TreeGiven the final colours on a tree after M path-painting updates with distinct colours, reconstruct the unique valid update order and the endpoints of each colour's shortest covering path. | Hard8 | TreeDFS+2 | No attempts yet | 0.7s | 512 MB | Judgeable |
| Cat and MouseOn a tree with distinct edge weights, the mouse always moves to its heaviest incident edge (or second heaviest if the cat blocks it); find the minimum number of mouse moves for the cat to trap it. | Hard8 | TreeDFS+2 | No attempts yet | 10s | 512 MB | Judgeable |
| Vera and the Engineering BuildingsGiven a tree of N nodes with distinct hidden values and inspection costs, find the minimum total cost of an adaptive strategy that is guaranteed to locate a local maximum. | Hard8 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| HH CountryFor each query set of tree vertices, output twice the sum of pairwise tree distances. | Hard8 | TreeDFS+1 | No attempts yet | 10s | 512 MB | Judgeable |
| LCA and queriesFor each query with a designated root r, report the LCA of u and v in a tree of up to 100,000 vertices. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Graph and Minimum Spanning TreeFor each edge of a connected weighted undirected graph, print the weight of a minimum spanning tree that is forced to include that edge. | Hard8 | Minimum spanning treeUnion-find+2 | No attempts yet | 2s | 512 MB | Judgeable |
| City MaintenanceGiven a tree with a price on every vertex, find the maximum, over all choices of a removed vertex, of the sum of the maximum price within each remaining connected component. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Arranging game levelsCount rooted tree arrangements of N levels where each level's clear score S_i and the cumulative score K_i along the root-to-level path are given, and children must have larger S than parents. | Hard8 | TreeCombinatorics+2 | No attempts yet | 1s | 256 MB | Judgeable |
| Programming Duel TournamentChoose a duel schedule for N contestants, where the higher skill always wins and each contestant duels at most L_i times, to maximize total duel XOR interest minus fatigue. | Hard8 | GreedyTree+2 | No attempts yet | 2s | 256 MB | Judgeable |
| Tree SeparatorGiven a tree, delete all vertices on some simple path between two chosen vertices; maximize the number of remaining components of size at least K. | Hard8 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Non-redundant DriveIn a tree where each node gives g fuel and each edge costs d, find the longest simple path from any start such that the running fuel never drops below zero, refueling once per node. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Äventyr 2On a tree, timelines get marked over time, and after each mark you must report the distance from a queried vertex to the nearest marked vertex. | Hard8 | TreeBFS+2 | No attempts yet | 1s | 256 MB | Judgeable |
| Cow at Large (Platinum)In a tree, for each barn find the minimum number of farmers placed at exits needed to catch Bessie, who starts there and runs for the nearest exit at equal speed. | Hard8 | TreeDFS+2 | No attempts yet | 4s | 512 MB | Judgeable |
| Cow at LargeOn a tree of N barns, find the minimum number of farmers placed at exits so they catch Bessie, who starts at node K and runs to any exit. | Hard8 | TreeBFS+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Factor-Free TreeGiven a sequence, decide whether it can be the inorder of a rooted binary tree where every node is coprime with all its ancestors, and if so output each node's parent index. | Hard8 | TreeDivide and conquer+2 | No attempts yet | 6s | 512 MB | Judgeable |
| The CaveOn a tree, decide whether one chamber lies on some walk from a_i to b_i using at most d_i edges, for every speleologist, and output the smallest such chamber. | Hard8 | TreeGraph+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Conquer the WorldArmies sit on the nodes of a weighted tree; move them along edges to satisfy each node's demand while minimizing total transport cost. | Hard8 | TreeDFS+1 | No attempts yet | 8s | 1024 MB | Judgeable |
| Wireless Instead of FiberGiven a connected multigraph, output a spanning tree minimizing the number of vertices whose degree differs from the original, following a prescribed construction procedure. | Hard8 | GraphGreedy+2 | No attempts yet | 2s | 1024 MB | Judgeable |
| New BarnsProcess online queries that add a leaf to a growing forest or ask for the eccentricity (distance to the farthest node) of a given node. | Hard8 | TreeGraph+2 | No attempts yet | 2s | 512 MB | Judgeable |
| DisruptionGiven a tree and extra weighted edges, for each tree edge report the minimum weight of a non-tree edge whose endpoints lie in different components after removing it. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| ExperienceGiven a rooted tree with values on nodes, partition nodes into vertex-disjoint downward paths to maximize the sum over paths of (max value minus min value). | Hard8 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| ANTSGiven a tree and a set of up to 50 marked nodes per query, find the node minimizing the sum of distances to all marked nodes, for up to 5000 queries. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| CitationsOrder the reading of a citation tree rooted at book 1 so that the sum of all book return times is minimized. | Hard8 | TreeGreedy+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| SubwayGiven two spanning trees on the same N stations, output a shortest sequence of weekend swaps, each removing one tree edge and adding another, so every intermediate graph stays a spanning tree and the target tree is reached. | Hard8 | GraphTree+2 | No attempts yet | 2s | 1024 MB | Judgeable |
| POPABuild a binary tree on indices with inorder order 0..N-1 and parent weights dividing child weights, using at most Q gcd-equality queries on hidden subarrays. | Hard8 | Divide and conquerTree+2 | No attempts yet | 1s | 512 MB | Judgeable |