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
TitleLevelTopicsSolvedTime limitMemory limitJudge
Balanced PathsCount ordered node pairs whose labels along the tree path form a balanced parenthesis string.Hard8Divide and conquerHash map+2No attempts yet3s256 MBJudgeable
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.Hard8Dynamic programmingTree+1No attempts yet5s256 MBJudgeable
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.Hard8GraphTreeNo attempts yet3s256 MBJudgeable
Sunlight on a TreeReport all nodes on the tree path from u to v whose dot product with the query direction is minimal.Hard8TreeSegment tree+1No attempts yet5s256 MBJudgeable
Special graphEdge deletions hit a functional graph while queries ask for the directed distance from a to b along the single outgoing walk.Hard8GraphTree+1No attempts yet1s64 MBJudgeable
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.Hard8GraphBFS+2No attempts yet2s256 MBJudgeable
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.Hard8Union-findTreeNo attempts yet5s512 MBJudgeable
CabinsFind the K-th smallest travel distance among all pairs of cabins placed on a weighted tree of river regions.Hard8Binary searchDivide and conquer+1No attempts yet6s64 MBJudgeable
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.Hard8Segment treeTree+1No attempts yet1.5s512 MBJudgeable
Fairland (Large)Keep the largest rooted connected subtree containing the CEO so all kept salaries fit within a range of width D.Hard8TreeSliding window+2No attempts yet10s512 MBJudgeable
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.Hard8Game theoryTree+1No attempts yet120s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet1s256 MBJudgeable
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.Hard8TreeDynamic programming+1No attempts yet2s512 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet1.5s256 MBJudgeable
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.Hard8TreePrefix sum+2No attempts yet10s512 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet4s256 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet3s512 MBJudgeable
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.Hard8TreeDynamic programming+1No attempts yet2s1024 MBJudgeable
NewspapersGiven a weighted tree, find the maximum average edge weight over all simple paths that contain at least k edges, printed to eight decimals.Hard8Binary searchDynamic programming+2No attempts yet4s1024 MBJudgeable
Sum of ScoresFind a non-empty vertex subset connected in both given trees whose score sum is maximized, with vertex counts up to 50.Hard8Dynamic programmingTree+1No attempts yet2s512 MBJudgeable
Hongjun and the Possible SetsCount the nonempty connected vertex subsets of a weighted tree whose maximum minus minimum weight is at most d.Hard8TreeDFS+2No attempts yet3s512 MBJudgeable
Hongjun and the TreeProcess subtree updates that add a distance-dependent value to each vertex, answering point-weight queries modulo 1e9+7.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
TreeMaintain a rooted tree under vertex deletions (children reparent to grandparent) and answer distance queries between two live vertices.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
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.Hard8TreeUnion-find+2No attempts yet4s512 MBJudgeable
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.Hard8Dynamic programmingTree+2No attempts yet10s512 MBJudgeable
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.Hard8Dynamic programmingTree+2No attempts yet3s512 MBJudgeable
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.Hard8TreeMath+2No attempts yet5s512 MBJudgeable
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.Hard8Dynamic programmingSorting+2No attempts yet5s512 MBJudgeable
Quarantine StationsPlace K quarantine barriers on the edges of a weighted tree so that the largest connected component's total population is minimized.Hard8TreeBinary search+1No attempts yet3s256 MBJudgeable
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.Hard8TreeUnion-find+2No attempts yet2s512 MBJudgeable
Cartesian TreeCount permutations of 1..N whose Cartesian tree has total child-position gap score at most S, modulo a prime.Hard8Dynamic programmingTree+1No attempts yet5s512 MBJudgeable
Two TreesPick a vertex subset connected in both of two trees to maximize the total score, with the empty set allowed.Hard8TreeDFS+1No attempts yet2s512 MBJudgeable
InterceptionPlace the fewest listening devices on the edges of a street-wide phone-line graph so that every given call route is covered.Hard8GraphGreedy+2No attempts yet8s512 MBJudgeable
Counting Similar TreesGroup labeled trees that are isomorphic under a bijection preserving edge label differences, and report each group size.Hard8TreeHash map+2No attempts yet2s512 MBJudgeable
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.Hard8GreedyTree+1No attempts yet4s512 MBJudgeable
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.Hard8TreePrefix sum+2No attempts yet5s512 MBJudgeable
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.Hard8TreeDivide and conquer+2No attempts yet2s512 MBJudgeable
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.Hard8TreeUnion-find+2No attempts yet2s512 MBJudgeable
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.Hard8TreeBinary search+2No attempts yet2s512 MBJudgeable
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).Hard8TreeBinary search+2No attempts yet2s512 MBJudgeable
Memory CellBuild the expression tree, find the largest pair of disjoint identical subtrees, and print the loser's postfix in lexicographic order.Hard8StackTree+2No attempts yet1s512 MBJudgeable
VirusGiven a binary tree, find the minimum number of nodes that end up infected when one node may be protected each round.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
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.Hard8Game theoryTree+2No attempts yet1s512 MBJudgeable
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.Hard8Dynamic programmingTree+2No attempts yet8s512 MBJudgeable
ACM TaxFor each query path in a weighted tree, output the median edge length, rounded to one decimal.Hard8TreeBinary search+2No attempts yet5s512 MBJudgeable
Dictionary GameWords are destroyed by prefix cuts; after each insertion into the dictionary, report which player wins the impartial game under optimal play.Hard8Game theoryTrie+2No attempts yet5s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
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.Hard8GreedyTree+2No attempts yet1s128 MBJudgeable
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.Hard8TreeDFS+2No attempts yet1s128 MBJudgeable
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.Hard8TreeDFS+2No attempts yet1s128 MBJudgeable
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.Hard8TreePrefix sum+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet2s256 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s64 MBJudgeable
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.Hard8TreeDynamic programming+1No attempts yet2s512 MBJudgeable
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.Hard8Dynamic programmingTree+2No attempts yet1s512 MBJudgeable
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.Hard8Dynamic programmingTree+2No attempts yet0.5s512 MBJudgeable
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.Hard8Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet1s1024 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet3s512 MBJudgeable
Balloon WarehouseSimulate repeated insertions into an infinite balloon line, then report the colors at positions l to r-1 after all instructions.Hard8TreeDFS+2No attempts yet7s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
CounterspellsAfter each of n leaf insertions into a rooted tree, find the minimum number of vertex recolorings needed to restore the unique well coloring.Hard8TreeDFS+2No attempts yet1s1024 MBJudgeable
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.Hard8TreeDFS+2No attempts yet0.5s1024 MBJudgeable
MousetrapOn a tree, Dumbo blocks or cleans edges while an edge-averse mouse moves; find the minimum moves to force it into the trap.Hard8TreeDFS+2No attempts yet5s512 MBJudgeable
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.Hard8TreeDynamic programming+1No attempts yet4s512 MBJudgeable
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.Hard8MathTree+2No attempts yet7s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet4s512 MBJudgeable
Hyunsoo CityGiven a connected cactus graph with toggleable edges, answer connectivity queries under edge updates, where each edge lies on at most one cycle.Hard8GraphDFS+2No attempts yet1s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s256 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet1s64 MBJudgeable
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.Hard8TreeDFS+2No attempts yet0.7s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet10s512 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
HH CountryFor each query set of tree vertices, output twice the sum of pairwise tree distances.Hard8TreeDFS+1No attempts yet10s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
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.Hard8Minimum spanning treeUnion-find+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
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.Hard8TreeCombinatorics+2No attempts yet1s256 MBJudgeable
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.Hard8GreedyTree+2No attempts yet2s256 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Ä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.Hard8TreeBFS+2No attempts yet1s256 MBJudgeable
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.Hard8TreeDFS+2No attempts yet4s512 MBJudgeable
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.Hard8TreeBFS+1No attempts yet2s512 MBJudgeable
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.Hard8TreeDivide and conquer+2No attempts yet6s512 MBJudgeable
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.Hard8TreeGraph+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDFS+1No attempts yet8s1024 MBJudgeable
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.Hard8GraphGreedy+2No attempts yet2s1024 MBJudgeable
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.Hard8TreeGraph+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
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).Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
CitationsOrder the reading of a citation tree rooted at book 1 so that the sum of all book return times is minimized.Hard8TreeGreedy+2No attempts yet1s1024 MBJudgeable
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.Hard8GraphTree+2No attempts yet2s1024 MBJudgeable
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.Hard8Divide and conquerTree+2No attempts yet1s512 MBJudgeable