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
| Title | Level | Topics | Solved | Time limit | Memory limit | Judge |
|---|---|---|---|---|---|---|
| Algorithm study membershipChoose two algorithm types for each of N members in a mentor tree so every team (a node plus its children) can assign distinct types to its members, minimizing total teaching cost. | Medium7 | Dynamic programmingTree+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Gangsters in Central CityOn a rooted tree, after each update marking a leaf as gangster-held, report the minimum pipes to clog and the fewest innocent houses left dry. | Medium7 | TreeGreedy+1 | No attempts yet | 2s | 256 MB | Judgeable |
| Tree and Queries 2Answer path-cost and k-th-vertex queries on a weighted tree with up to 100,000 nodes and queries. | Medium7 | TreeBinary search+2 | No attempts yet | 2s | 512 MB | Judgeable |
| First black vertex on a pathFlip vertex colors and, along the root-to-v path, report the first black vertex encountered from the root. | Medium7 | TreeSegment tree+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Maximum weight in a monochromatic componentOn a colored tree, handle color flips, weight updates, and queries for the maximum weight in the monochromatic component containing a vertex. | Medium7 | TreeSegment tree+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Power SupplyGiven a tree whose vertices are supplies or demands and whose edges have capacities, decide if deleting some edges yields subtrees each holding exactly one supply that meets its demands. | Medium7 | TreeDFS+1 | No attempts yet | 1s | 512 MB | Judgeable |
| Merging treesGiven a left-handed and a right-handed ternary tree, find the minimum number of vertices in a ternary tree that is a superposition of both. | Medium7 | TreeDynamic programming+1 | No attempts yet | 1s | 512 MB | Judgeable |
| Curious GuardiansCount labeled trees on N cities where every vertex has degree at most K. | Medium7 | CombinatoricsDynamic programming+1 | No attempts yet | 1s | 512 MB | Judgeable |
| Entangled TreeGiven a forest of split nodes, order the leaf labels so each split node's leaves are consecutive, choosing the lexicographically smallest sequence, then answer position queries. | Medium7 | TreeDFS+2 | No attempts yet | 8s | 512 MB | Judgeable |
| Trees and PrimesGiven a tree on N vertices, find the probability that a uniformly random pair of distinct vertices has a prime distance. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Tree StandsCount the K-vertex subsets of a tree in which every chosen vertex is adjacent to at least one other chosen vertex, modulo 1000000007. | Medium7 | TreeDynamic programming+1 | No attempts yet | 5s | 512 MB | Judgeable |
| Quality ExpressionsGiven a bracket expression with ? placeholders and per-arity limits, choose values so the expression is valid and its value is as large as possible. | Medium7 | Dynamic programmingTree+1 | No attempts yet | 1s | 64 MB | Judgeable |
| Performance ReviewFor each employee, sum t_j over all descendants j whose rank r_j is lower than the employee's rank. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Tree and PrimesIn a tree, count pairs of nodes whose path length is prime, and output the probability as a reduced fraction. | Medium7 | TreeDFS+1 | No attempts yet | 3s | 512 MB | Judgeable |
| Promotion CountingFor each node of a rooted tree, count descendants whose value is larger than the node's own value. | Medium7 | TreeDFS+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Heaps from TreesGiven a rooted tree with a value at each node, find the largest subset in which every ancestor-descendant pair has the ancestor's value strictly larger. | Medium7 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Junoh is top talent!!In a weighted tree, find a simple path with the maximum number of nodes, then among those pick the one with the smallest total edge weight, and report that weight divided by T rounded up. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Grasshopper RouteGiven a tree and two vertices s and t, construct the specific valid Grasshopper route defined by a recursive rule on the path components. | Medium7 | TreeDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Tree VisitsMaintain a value X under increments of 2^C modulo 2^N, mark all nodes on each root-to-leaf walk, and report the count of distinct visited nodes. | Medium7 | TreeBit manipulation+2 | No attempts yet | 5s | 1536 MB | Judgeable |
| AntsEach room of a weighted tree rooted at room 1 holds an ant with limited energy; for every ant, find the closest-to-root room it can reach moving toward room 1. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 256 MB | Judgeable |
| Gates of uncertaintyGiven a binary tree of two-input NAND gates where some gates may be stuck, count input assignments that make the faulty circuit differ from the fault-free one. | Medium7 | TreeDynamic programming+1 | No attempts yet | 1s | 1024 MB | Judgeable |
| Keeping On TrackGiven a tree with n+1 nodes, find the node whose removal splits it worst, then pick the best non-edge to add so the remaining disconnected pairs are minimized. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| ASCII Art TreesFor each prefix-encoded binary tree, draw its ASCII layout using the given slash, bar, and spacing rules and print the resulting character grid. | Medium7 | TreeRecursion+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Justified JungleGiven a tree with n nodes, find every k such that removing exactly k edges leaves a forest whose connected components all have the same size. | Medium7 | TreeDFS+2 | No attempts yet | 6s | 512 MB | Judgeable |
| KDH, Son of the TyphoonOn a tree where every pair of vertices adds 1 traffic to each path edge, vertices survive independently with probability p; find the expected total traffic. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| LoL TournamentGiven a tournament bracket where each winner is renumbered, find which starting positions give the highest chance of winning all n-1 rounds with per-round win probability p. | Medium7 | GraphTree+2 | No attempts yet | 5s | 512 MB | Judgeable |
| Divide and ConquerEach of two kings owns a spanning tree on N towns; find the fewest roads to destroy so some pair becomes disconnected and count the minimum-size cut sets. | Medium7 | TreeGraph+2 | No attempts yet | 2s | 64 MB | Judgeable |
| Company PicnicIn a tree of employees with speeds, pair each node with at most one neighbor on the parent-child edge, maximizing team count then average team speed. | Medium7 | TreeDynamic programming+1 | No attempts yet | 2s | 512 MB | Judgeable |
| We Don't Wanna Work!Maintain a dynamic set of members whose top floor(20%) by motivation and join time are workhorses, and log every time a member's status flips after each join or departure. | Medium7 | TreeSorting+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Similarity of SubtreesFor every node, count how many nodes share its depth profile in the rooted tree; sum the number of pairs with identical profiles. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Delivery GuyOn a tree of N restaurants with demand A_i, maximize total delivered peppers in M time units, where each visit costs 1 to deliver and each edge costs 1 to traverse. | Medium7 | TreeDynamic programming+2 | No attempts yet | 2s | 64 MB | Judgeable |
| A Particle on the TreeFor each query edge (U,V) and final color C, count pairs (start, end) whose shortest path uses that edge in that direction and whose arrival color matches C. | Medium7 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Calculate! 2On a rooted tree, handle subtree XOR queries and subtree XOR updates, printing the XOR of a vertex and its descendants. | Medium7 | TreeSegment tree+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Thor's JourneyIn a perfect binary tree of up to 2^17-1 nodes with node weights, count for each query (start node A, target sum D) how many nodes B lie on a path from A with sum D. | Medium7 | TreePrefix sum+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Network HackingGiven a weighted tree, cut one edge, then reconnect its two endpoints with an edge of the same weight to maximize the resulting tree's diameter. | Medium7 | TreeDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Balanced TreesCount perfectly balanced trees of weight N, where a tree splits into k identical subtrees each of the largest weight summing within the parent's weight. | Medium7 | TreeNumber theory+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Tree and GahuiIn a heap-indexed complete binary tree, answer subtree-size queries and subtree-removal queries as nodes get deleted over time. | Medium7 | TreeSegment tree+2 | No attempts yet | 1.5s | 512 MB | Judgeable |
| Tree and PolynomialsApply subtree path polynomial updates and print each vertex's final value modulo 1,000,000,007. | Medium7 | TreeMath+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Path EmbeddingGiven a tree and an ordering of its vertices, find the maximum tree distance between consecutive vertices in the ordering, capping the answer at 99. | Medium7 | TreeLinked list+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Space StationGiven a tree with weighted edges, find the minimum time to start at node 1, traverse every edge at least once, and return, where up to M jumps between any two modules cost K each. | Medium7 | TreeDynamic programming+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Prime Tree - 1Relabel the vertices of each given tree with the integers 1 to n to minimize the number of edges whose endpoints share a common divisor. | Medium7 | GreedyNumber theory+2 | No attempts yet | 10s | 512 MB | Judgeable |
| EmpireSimulate a tree of kingdoms and wars: process each battle in order, transfer vassal subtrees on losses and successful rebellions, then report the root kingdoms sorted by ASCII order. | Medium7 | TreeSimulation+2 | No attempts yet | 1s | 256 MB | Judgeable |
| ImputationAssign A, T, C, or G in place of each '?' on tree leaves to minimize total transition costs along edges, summed over all string positions independently. | Medium7 | Dynamic programmingTree+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Rainwater on a TreeWater starts at the root and each vertex sends 1 unit per second to a uniformly random child; find the average expected final water over vertices that hold any water. | Medium7 | TreeProbability+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Why the Mole Came Up to Jeongbo IslandOn a weighted tree, sum the minimum edge weight over all unordered pairs of vertices. | Medium7 | TreeUnion-find+2 | No attempts yet | 2s | 512 MB | Judgeable |
| First of Her NameGiven a family tree where each lady's name is her first letter prepended to her mother's name, count for each query string how many lady names have it as a prefix. | Medium7 | StringTrie+2 | No attempts yet | 10s | 512 MB | Judgeable |
| Cow EvolutionGiven N distinct feature sets for cow sub-populations, decide whether they can arise from an evolutionary tree in which every feature first appears on exactly one edge. | Medium7 | TreeRecursion+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Rail GaugesAssign real gauges to domestic stations in a tree whose leaves are foreign stations with fixed gauges, minimizing the sum of absolute differences along edges, and output the floor of the minimum. | Medium7 | TreeGreedy+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Appeal to the AudienceAssign k given skill values to the k leaves of a rooted tree to maximize the sum over all internal nodes of the skill values in that node's subtree's leaves. | Medium7 | TreeGreedy+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Low Effort LeagueGiven 2^r teams in a fixed knockout bracket, find the minimum total training hours so team 1 wins, where beating a stronger team costs the squared skill gap. | Medium7 | Dynamic programmingTree+2 | No attempts yet | 3s | 512 MB | Judgeable |
| Big Company Seungbeom'sGiven a rooted tree of employees, pick a matching of edges where each node touches at most one chosen edge, maximizing the sum of products of endpoint skill values. | Medium7 | TreeDynamic programming+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Bus RoutesCover every edge of a tree with the fewest simple paths, where each path visits distinct vertices in order along tree edges. | Medium7 | TreeDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Gene TreeGiven an unrooted tree with positive edge lengths and up to 100,000 nodes, compute the sum of squared path-lengths over all unordered pairs of leaves. | Medium7 | TreeDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Flow FinderGiven a rooted tree with some known vertex flows, where every leaf is a free positive integer and each internal node equals the sum of its children, decide whether all flows are uniquely determined and output them, otherwise print impossible. | Medium7 | TreeDFS+2 | No attempts yet | 4s | 512 MB | Judgeable |
| Insertion OrderFind a permutation of 1 to n whose insertion order into an unbalanced BST yields a tree of height exactly k, or report impossible. | Medium7 | TreeGreedy+2 | No attempts yet | 2s | 512 MB | Judgeable |
| EquidistantGiven a tree and a set of marked vertices, find any vertex equidistant from all marked vertices, or report that none exists. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Parallel UniverseGiven up to a million small trees (each up to 30 nodes), count how many are pairwise non-isomorphic, since Hanna can photograph one tree per distinct topology. | Medium7 | TreeHash map+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| Radio PrizeIn a weighted tree, for every city u output the sum of (t[u] + t[v]) * dist(u, v) over all other cities v. | Medium7 | TreeDFS+2 | No attempts yet | 3s | 512 MB | Judgeable |
| Milk VisitsGiven a tree with a cow type at each node, answer for each of M queries whether a node on the path from A to B has type C. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Allergic AronGiven a weighted tree, choose a connected set of edges maximizing (number of edges) times (minimum edge weight in the set). | Medium7 | TreeUnion-find+2 | No attempts yet | 1s | 512 MB | Judgeable |
| PutovanjeOn a tree, visit towns 1 through N in order; each edge costs C1 per traversal or C2 once, so minimize total ticket cost. | Medium7 | TreeGreedy+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Company Culture 5A supervisor tree supports turning all subordinates of a worker on or off, and counting how many subordinates of a worker are currently on. Initially only the computer of node 1 is on. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Best TreeGiven the degree sequence of a tree, find the maximum possible size of a maximum matching over all trees realizing that sequence. | Medium7 | TreeGreedy+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Christmas TreeMaintain a dynamic set of colored nodes in a rooted tree under insertions and deletions, and after each update report the lowest common ancestor of all colored nodes. | Medium7 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| UberficationIn an undirected unit graph, sum the shortest path distances over all unordered pairs of nodes that are connected by exactly one simple path. | Medium7 | GraphDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| ㄷㄷㄷㅈGiven a tree with up to 300,000 vertices, count the four-vertex subsets whose induced shape is the path-like 'ㄷ' versus the star-like 'ㅈ', and compare the counts against the ratio 3. | Medium7 | CombinatoricsTree+2 | No attempts yet | 2s | 1024 MB | Judgeable |
| Bridge ReinforcementGiven a graph with maximum degree 2, count the minimum-size edge subsets whose connectivity components match the original graph, modulo 1e9+7. | Medium7 | GraphCombinatorics+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Magic SwordsGiven n ages, build a forest where each node has at most two children and every child is at least k years younger than its parent, or report that none exists. | Medium7 | GreedySorting+2 | No attempts yet | 2s | 512 MB | Judgeable |
| IslandsGiven a grid of 8-connected islands and 4-connected seas, determine which islands enclose other islands and output island counts grouped by nesting height. | Hard8 | BFSGraph+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Kruskal's BallGiven a graph with unique edge weights, build a Kruskal reconstruction tree to answer queries about the minimum temperature needed to connect two vertices and the size of the reachable component at that temperature. | Hard8 | Minimum spanning treeUnion-find+2 | No attempts yet | 2s | 128 MB | Judgeable |
| NetworkCount non-isomorphic trees on N+1 nodes where one fixed hub node has any degree but every other node must have odd degree. | Hard8 | CombinatoricsTree+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Terminal CitiesGiven a connected graph with up to 15 cities, find a spanning tree that maximizes the number of vertices with degree exactly one. | Hard8 | Dynamic programmingBit manipulation+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Second Smallest Spanning TreeFind the minimum spanning tree, then compute the smallest spanning tree whose weight is strictly greater than the MST weight, or report -1 if none exists. | Hard8 | Minimum spanning treeTree+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Complete Binary TreeGiven two same-height complete binary trees whose leaves carry a permutation of labels, find the largest label subset whose pairwise leaf distances match in both trees. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 5s | 128 MB | Judgeable |
| Traffic SystemGiven a connected graph of cities and roads, answer many queries asking if two cities stay connected after deleting one specific road or all roads of a chosen city. | Hard8 | GraphDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Tree ColoringGiven a rooted tree with node weights, find the minimum total cost of coloring all nodes in an order that respects parent-before-child, where each node's cost is weight times its coloring position. | Hard8 | GreedyTree+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Log TransportGiven a tree of villages flowing into a kingdom, choose k extra sawmill locations to minimize the total weight times distance cost of routing each village's logs to its nearest downstream mill. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Tree Height ReductionGiven a rooted tree and target height H, find the minimum total cost of repeatedly reattaching vertices to ancestors (cost based on level gap) to bring the tree height down to at most H. | Hard8 | TreeDynamic programming+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Broadcast NetworkPick which edges of a rooted tree to install so that total user fees minus installation cost stays non-negative while maximizing the number of served users, solved with tree knapsack DP. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Building a Tree ModelGiven a tree, find the minimum number of non-branching path segments (strings) needed to cover every edge exactly once, then minimize the length of the longest such string. | Hard8 | TreeDynamic programming+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Balance ScalePlace weights 1..n into two mirror-shaped binary trees filled level by level under BST-like ordering rules so both sides balance in total weight, or report impossible. | Hard8 | TreeSimulation+2 | No attempts yet | 1s | 512 MB | Judgeable |
| High SpiesGiven a tree of ports with observed directed edge flows, compute the minimum and maximum containers that could have traveled between two leaf countries, respecting the no-immediate-return constraint at each port. | Hard8 | TreeGreedy+2 | No attempts yet | 2s | 128 MB | Judgeable |
| MazeGiven a tree-like maze grid, compute the expected number of steps for a random depth-first exploration (choosing unvisited branches uniformly, backtracking on dead ends) to travel from entrance to exit. | Hard8 | TreeDFS+2 | No attempts yet | 2s | 128 MB | Judgeable |
| PrevtreeGiven the display code sequence (leaf-counts of root and left-children) of a strict binary tree, reconstruct the tree and output the lexicographically previous valid display code with the same leaf count, or 0 if none exists. | Hard8 | TreeRecursion+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Reducing Tree HeightGiven a weighted rooted tree, find the minimum total edge-weight reduction needed so every root-to-leaf distance is at most H. | Hard8 | TreeDynamic programming+1 | No attempts yet | 2s | 128 MB | Judgeable |
| HospitalsGiven a tree with populations and hospital villages, allocate a limited road-improvement budget with a per-road floor to minimize total or maximum travel time to the nearest hospital. | Hard8 | TreeGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Emergency CenterGiven a graph that is a cycle with trees hanging off it, place two facilities at stations to minimize the maximum shortest-path distance from any station to its nearest facility. | Hard8 | GraphTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Tree PartitionChoose exactly K vertices in a weighted tree to minimize the total weight of edges whose endpoints share the same chosen/unchosen status, and output the chosen vertex set. | Hard8 | Dynamic programmingTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Bus RoutesGiven a tree with degree at most 10, partition all edges into leaf-to-leaf simple paths covering every vertex while minimizing the maximum path length, or report impossibility. | Hard8 | TreeGreedy+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Cargo Truck Collection RoutesGiven a tree rooted at the depot with cargo weights at nodes, plan truck trips of capacity 10 minimizing total travel distance, splitting cargo as needed, and output the routes. | Hard8 | TreeGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Mars Bacteria LineupGiven a repulsion matrix, choose left/right swap at every node of a complete binary tree to minimize the total sum of adjacent-pair distances in the resulting leaf permutation. | Hard8 | Dynamic programmingTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Antarctic ScientistsCompute the exact character count needed to render an ASCII family tree with fixed box drawing and branching link rules given a forest with up to two children per node. | Hard8 | TreeRecursion+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Antarctic ExpeditionProcess bridge, penguin-update, and route-sum queries on an incrementally connected forest, requiring dynamic connectivity checks and path-sum queries under updates. | Hard8 | Union-findTree+2 | No attempts yet | 5s | 128 MB | Judgeable |
| Bicycle RaceGiven a graph where every edge belongs to at most one cycle, find the longest walk ending at city 1 using each edge at most once. | Hard8 | TreeDynamic programming+1 | No attempts yet | 1s | 128 MB | Judgeable |
| ParkingGiven a rooted tree garage with occupied rooms, find the minimum number of car pushes to clear the path from room P to the exit root, or report impossibility. | Hard8 | TreeGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Graphic MadnessDecide whether a Hamiltonian cycle exists in a combined structure formed by two trees (with socket/processor degree rules) joined by a perfect matching between their sockets. | Hard8 | GraphTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| AntsGiven a forest of towns formed by persistent range-add copies of parent towns, answer range-sum queries on each newly created version using online, XOR-derived parameters that depend on previous answers. | Hard8 | Segment treePrefix sum+2 | No attempts yet | 3s | 128 MB | Judgeable |
| Cactus RevolutionDecide whether a given cactus graph can be split into k connected districts of equal size n/k, using cactus structure properties. | Hard8 | GraphDynamic programming+1 | No attempts yet | 1s | 128 MB | Judgeable |
| BridgesChoose k edges of a weighted tree to convert to a faster speed so that the sum of travel times over all pairs is minimized, breaking ties lexicographically. | Hard8 | TreeGreedy+2 | No attempts yet | 2s | 64 MB | Judgeable |
| Bee GardenGiven a tree of hives with coordinates, find which single new edge added minimizes the doubled-tree traversal, i.e. maximizes edge weight removed twice minus new edge distance, tie-broken lexicographically. | Hard8 | TreeDynamic programming+1 | No attempts yet | 2s | 64 MB | Judgeable |