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 |
|---|---|---|---|---|---|---|
| Party at Hali-BulaGiven a company hierarchy tree, find the largest set of employees with no boss and employee both chosen, and report whether that maximum set is unique. | Medium6 | TreeDynamic programming+2 | No attempts yet | 1s | 128 MB | Judgeable |
| ReorganizationGiven each employee's rank in ID order, decide whether a binary hierarchy exists where every non-root has a supervisor with a smaller ID and a better rank. | Medium6 | GreedyTree+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Tree PruningGiven a rooted binary tree with colored nodes, prune subtrees to make the whites minus blacks equal exactly D, minimizing the number of prunes. | Medium6 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| HerdingPlace the fewest traps on a grid of arrows so that a cat starting anywhere and following arrows forever eventually enters a trapped cell. | Medium6 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| QuadtreesGiven two quadtree preorder strings for 32x32 black-and-white images, count the black pixels in their union by recursively merging overlapping quadrants. | Medium6 | RecursionTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Tree IsomorphismGiven two rooted trees in pre-order with '#' closing each node's child list, decide whether the trees are isomorphic ignoring node labels. | Medium6 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| JourneyGiven a weighted tree, a start city k, and a set of target cities, find the length of the shortest walk from k that visits every target at least once. | Medium6 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Turning a TreeReroot a given ordered tree at a specified leaf so the counter-clockwise order of neighbors at each node stays the same, then print the new tree. | Medium6 | TreeDFS+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| BonsaiRoot a weighted tree and cut edges of minimum total weight so that no original leaf stays connected to the root. | Medium6 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Three-Coloring of Binary TreesGiven a binary tree as a digit specification, color each node red, green, or blue so adjacent nodes differ and siblings differ, then report the maximum and minimum number of green nodes. | Medium6 | TreeDFS+2 | No attempts yet | 3s | 128 MB | Judgeable |
| BackpackChoose a set of items whose total mass is at most p, where each chosen item requires its named lower-indexed prerequisite to be chosen too. | Medium6 | Dynamic programmingTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Road Network 2Count the labeled trees that realize a prescribed degree sequence, or report that none exist, with n up to two million. | Medium6 | TreeCombinatorics+1 | No attempts yet | 5s | 128 MB | Judgeable |
| MatchingsGiven a tree, compute the size of its maximum matching and count how many maximum matchings exist, modulo m. | Medium6 | Dynamic programmingTree+2 | No attempts yet | 3s | 128 MB | Judgeable |
| Binary Search TreeCount the insertion orders that build the same binary search tree as the given permutation. | Medium6 | CombinatoricsTree+1 | No attempts yet | 2s | 256 MB | Judgeable |
| Binary Search Tree 2Count the permutations of 1 to N that build the same binary search tree as the given permutation. | Medium6 | CombinatoricsTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Unscrambling ImagesThe solver recovers the hidden child order at each quadtree node from the test encoding and restores the secret image. | Medium6 | TreeRecursion+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Klingon WarfarePick one subclan from each ordered clan tree so the pair matches in style, child count and sibling order with the largest size. | Medium6 | TreeHash map+1 | No attempts yet | 5s | 128 MB | Judgeable |
| String Insert and PrintMaintain a single string under positional insertions and print the requested substring for each query. | Medium6 | TreeString+1 | No attempts yet | 10s | 256 MB | Judgeable |
| Cartesian TreeBuild the Cartesian tree whose inorder follows one key and heap order follows the other, printing parents and children, or NO when impossible. | Medium6 | StackSorting+1 | No attempts yet | 2s | 64 MB | Judgeable |
| Sky CitiesAdd the fewest bridges so the connected cities stay connected after any single bridge fails, and print the pairs fixed by the leaf-pairing rule. | Medium6 | DFSGraph+1 | No attempts yet | 1s | 256 MB | Judgeable |
| TreeSupport parent changes, path recoloring, and distinct-color path queries on a dynamic rooted tree. | Medium6 | TreeBrute force+1 | No attempts yet | 3s | 256 MB | Judgeable |
| Chicken JoggersPlace the fewest extra lamps so every trail a jogger who starts at intersection 1 and returns after exactly S meters could use has a lamp on one end. | Medium6 | Dynamic programmingTree+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Adjoin the NetworksJoin the forest of cable trees with the fewest new links so the connected network has the smallest possible diameter, and report that diameter. | Medium6 | TreeGreedy+2 | No attempts yet | 1s | 256 MB | Judgeable |
| Farthest node in a weighted treeFor every node of a weighted tree with up to 50000 nodes, print its distance to the farthest node. | Medium6 | TreeDFS | No attempts yet | 1s | 256 MB | Judgeable |
| Bundles of JoyBuy the cheapest set of nested or disjoint bundles that covers every dessert type. | Medium6 | Dynamic programmingTree | No attempts yet | 3s | 256 MB | Judgeable |
| Special Christmas TreeFind the maximum node count of a binary tree with exactly L leaves and height at most H. | Medium6 | MathGreedy+1 | No attempts yet | 3s | 256 MB | Judgeable |
| Max FlowCount how many of the K given tree paths pass through each stall and report the largest count. | Medium6 | TreePrefix sum+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Symmetric Trees (Small)Decide whether a colored tree with at most 12 vertices admits a planar straight-line drawing with a vertical line of symmetry. | Medium6 | Brute forceTree+1 | No attempts yet | 5s | 512 MB | Judgeable |
| Rational Number TreeGiven the infinite binary tree that lists every positive rational once, find the nth fraction in level order and the level-order position of a given fraction. | Medium6 | MathNumber theory+2 | No attempts yet | 5s | 512 MB | Judgeable |
| World Cup 2010 (Small)Buy the cheapest set of knockout match tickets so each team misses at most its allowed number of games whatever the results. | Medium6 | Dynamic programmingTree | No attempts yet | 5s | 512 MB | Judgeable |
| Rainbow TreesCount edge colorings of a small tree with k colors so that any two or three consecutive edges on a path get distinct colors, modulo 1e9+9. | Medium6 | Dynamic programmingTree+1 | No attempts yet | 5s | 512 MB | Judgeable |
| Mixing Bowls (Small)Given a recipe tree of mixtures, find the minimum number of bowls needed by choosing the order of preparation. | Medium6 | TreeDFS+1 | No attempts yet | 5s | 512 MB | Judgeable |
| Modern Art PlagiarismDecide whether the smaller tree is isomorphic to some subtree cut from the larger tree. | Medium6 | TreeDFS+1 | No attempts yet | 50s | 512 MB | Judgeable |
| SwapGiven a permutation, decide for each k = 2..n whether to swap position k with floor(k/2), producing the lexicographically smallest reachable sequence. | Medium6 | GreedyTree+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Republic of InhanicaGiven a tree rooted at island 1, cut a minimum-cost set of edges so that every leaf other than the root is disconnected from the root. | Medium6 | TreeDynamic programming | No attempts yet | 1s | 256 MB | Judgeable |
| UniversitiesOn a tree whose nodes are black or white with weighted happiness, find the maximum total weight of a path that contains equally many black and white nodes. | Medium6 | TreePrefix sum+1 | No attempts yet | 1s | 1024 MB | Judgeable |
| Building a GraphBuild a connected graph (tree) with N nodes and N-1 edges, where each node's score depends on its degree, and maximize the total score. | Medium6 | TreeDynamic programming+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Tree CountryCount the subsets of K vertices in a tree that form a connected subtree, modulo 1e9+7. | Medium6 | Dynamic programmingTree+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Happy TreeFind the minimum number of leaves to remove so that no remaining vertex has a descendant whose path distance exceeds that descendant's value. | Medium6 | TreeDFS+1 | No attempts yet | 2s | 512 MB | Judgeable |
| A Dark Flame Dragon Sleeps in My Left HandFor each node in a weighted tree, find the distance to the farthest other node (the tree's eccentricity). | Medium6 | TreeDFS+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Sum of subtree sizesCount all connected subgraphs of a tree and output the sum of their vertex counts modulo 1e9+7. | Medium6 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| TreeGiven a rooted tree, process a mix of edge deletions and connectivity queries in order, answering YES or NO for each query. | Medium6 | Union-findTree+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Carrot FarmMaintain a set of disjoint planted intervals under plant and harvest operations; after each, report the empty or planted area directly left and right of the affected span. Each area is (number of columns) times L. | Medium6 | IntervalsTree+2 | No attempts yet | 3s | 512 MB | Judgeable |
| Lost in the NightOn a tree, a walker starting at node A repeatedly picks a uniformly random neighbor until reaching hotel B or C; find the probability of hitting B first. | Medium6 | ProbabilityGraph+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Fighting cancerGiven two trees on atoms 1..N, decide whether they are isomorphic as unlabeled graphs and print S or N. | Medium6 | TreeDFS+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Alien Creature NumberingCount the labelings of a complete binary tree of height H with 1..2^(H+1)-1 where every parent's label is smaller than its children's labels, modulo 1e9+7. | Medium6 | CombinatoricsTree+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Free FigurinesGiven two valid nesting configurations of n matryoshka dolls, find the minimum number of place and take-out moves to transform one into the other. | Medium6 | TreeGreedy+1 | No attempts yet | 1s | 512 MB | Judgeable |
| Phonomenal ReviewsGiven a tree and a set of M marked nodes, find the minimum number of edges Jo must walk to visit every marked node, starting anywhere. | Medium6 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Sequence and Queries 17Maintain an array under point updates and answer range-minimum queries over subarrays. | Medium6 | Segment treeArray+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Marbles on the treeGiven a rooted ordered binary tree, find the leaf where the K-th marble stops, where each marble at a two-child node goes to the left if left subtree has at most the right subtree's resting marbles, else right. | Medium6 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Ant NestGiven paths of food names from the top floor down, print the merged tree with each node indented by two dashes per depth and children in dictionary order. | Medium6 | TrieTree+2 | No attempts yet | 1s | 256 MB | Judgeable |
| Balanced TreeGiven a tree whose vertices each hold A or B, swap characters along edges so no edge joins equal letters, using the fewest swaps, or report -1. | Medium6 | TreeDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Hidden HierarchyBuild a directory tree from file paths, and print the smallest set of directories (expanding or collapsing as needed) that covers every directory whose total size is at least t. | Medium6 | TreeHash map+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Decisions, DecisionsGiven the truth table of an n-variable boolean function, count the vertices in its unique minimal binary decision diagram. | Medium6 | Dynamic programmingDivide and conquer+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Barn PaintingCount the proper 3-colorings of a tree consistent with some pre-colored nodes, modulo 1e9+7. | Medium6 | TreeDynamic programming+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Tournament ChartParse a knockout bracket given as a string and decide whether the reported win counts for all players can be consistent with some assignment of match winners. | Medium6 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Pepper WreathGiven a tree whose vertices carry non-negative weights and a cap k, find the minimum number of edges to cut so every resulting component has total weight at most k. | Medium6 | TreeDFS+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| Directory TraversalGiven a directory tree, choose a directory that minimizes the total length of all relative paths from it to every file. | Medium6 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Tree Country Tour GuideGiven the move sequence of a shortest round trip that visits every node of an unknown rooted tree, reconstruct each city's parent. | Medium6 | StackTree+1 | No attempts yet | 1s | 512 MB | Judgeable |
| Tree and ColorsGiven a rooted tree with colored vertices and queries f(v,c) counting subtree vertices of color at most c, print the sum of all answers modulo 1e9+7. | Medium6 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Two RobotsOn a weighted tree, two robots at given nodes must meet on some edge or its endpoints; find the minimum combined distance traveled. | Medium6 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Prime Tree - 3Relabel a tree's vertices with 1 to n to minimize edges whose endpoints share a prime factor, and output the labeling for every test case. | Medium6 | TreeGreedy+2 | No attempts yet | 10s | 512 MB | Judgeable |
| Lost MapGiven an all-pairs distance table of an unknown tree with n up to 2500, recover the tree by its n-1 edges. | Medium6 | TreeGraph+1 | No attempts yet | 5s | 512 MB | Judgeable |
| DebloGiven a tree with numbers on its nodes, add up the XOR of every node-value along every path between two nodes, counting single-node paths too. | Medium6 | TreeBit manipulation+2 | No attempts yet | 1s | 512 MB | Judgeable |
| DFS Special JudgeGiven a tree and a permutation of its vertices, decide whether that permutation can be the DFS visit order starting from vertex 1. | Medium6 | DFSTree+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Life in WartimeGiven N distinct cities (all below 250) in an infinite binary heap tree, count cities that either host a unit or lie on the unique path between two units. | Medium6 | TreeHash map+2 | No attempts yet | 2s | 512 MB | Judgeable |
| StrapsChoose a set of straps forming a rooted tree: each strap occupies one port of its parent, one strap hangs from the phone, and total happiness is maximized. | Medium6 | Dynamic programmingTree+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Give Me Back My Binary Tree!!!Count the number of distinct binary trees with exactly E edges, where mirror images count as different trees, modulo 1e9+7. | Medium6 | Dynamic programmingCombinatorics+2 | No attempts yet | 2s | 1024 MB | Judgeable |
| Bob in WonderlandGiven a tree of N connected links, find the minimum number of link reconnections needed to turn it into a path (each vertex has degree at most two). | Medium6 | TreeGreedy+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Milk VisitsGiven a tree with each node labeled G or H, answer queries asking whether the path between two nodes contains at least one node of a given label. | Medium6 | TreeDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Nested Set ModelRoot an undirected tree at S, traverse children in ascending order, and label each node with nested left/right interval numbers. | Medium6 | DFSTree+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| ExpeditionEach candidate forbids at most one other candidate; choose the largest subset where no included candidate's forbidden partner is also included. | Medium6 | GraphGreedy+2 | No attempts yet | 2s | 512 MB | Judgeable |
| European TripChoose N-1 roads to keep every country connected, then find the closed tour that pays each road cost twice plus visit costs, and return the least total. | Medium7 | Minimum spanning treeGraph+2 | No attempts yet | 2s | 128 MB | Judgeable |
| WarGiven a forest of vassal relations and per-country conquest costs, find the minimum days needed to conquer or force surrender of at least M countries using tree knapsack DP. | Medium7 | Dynamic programmingTree+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Special NodesIn a rooted tree where child weights exceed parent weights, mark vertices special or ordinary to minimize the total of each ordinary vertex's weight minus its nearest special ancestor's weight. | Medium7 | Dynamic programmingTree+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Binary Search TreeGiven the insertion order of 0..N-1 values, compute the sum of node heights in the resulting binary search tree efficiently for N up to 250000. | Medium7 | TreeDivide and conquer+2 | No attempts yet | 2s | 256 MB | Judgeable |
| Treasure HuntGiven a tree of rooms, compute the minimum worst-case number of queries needed to locate a hidden treasure using an optimal centroid-based questioning strategy. | Medium7 | TreeDivide and conquer+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Binary Tree DrawingGiven a binary tree reconstructed from preorder and inorder traversals, compute the minimum area of a grid drawing where each right child extends the row and each down child extends the column. | Medium7 | Dynamic programmingTree+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Compare Tree Traversal PathsGiven two 0/1 Euler-tour strings from DFS traversals of a tree rooted at the same vertex, decide whether both could come from the same underlying tree. | Medium7 | TreeString+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Tree Path PartitionGiven a tree and integer K, find the minimum number of vertex-disjoint paths of length at most K that cover all vertices. | Medium7 | TreeGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Magic Colored PaperSimulate recursive cutting of a sheet into black/white pieces by successive points, tracking each piece's rectangle, and report the largest and smallest resulting areas. | Medium7 | SimulationBinary search+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Emergency Contact NetworkDesign a fastest call schedule so a class leader's contact network reaches every student, respecting call directions and one-call-per-student, minimizing total minutes. | Medium7 | TreeGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Salary IncreaseFor each new employee added to a hierarchy tree, count how many ancestors get their salary raised to match the new hire's salary until the chain stabilizes. | Medium7 | TreeBinary search+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Road RepairGiven a tree with per-edge reducible travel times and a total repair budget, minimize the maximum distance from city 1 to any other city by optimally allocating budget across edges. | Medium7 | Binary searchTree+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Railway Route CoverGiven a tree, partition all vertices into vertex-disjoint paths covering every node so that the total edge weight used by the paths is maximized, using tree DP. | Medium7 | Dynamic programmingTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Tram Line ColoringGiven a tree covered by paths (tram lines) that share stations, assign colors to lines so that lines sharing a station differ, using the minimum number of colors. | Medium7 | GraphGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Two Snow PlowsGiven a tree rooted at S, find minimum total edge traversal cost for two walks starting at S that together cover every edge, without returning to S. | Medium7 | TreeDynamic programming+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Royal TreasuryGiven a tree hierarchy, find the maximum matching between parent-child pairs and count the number of maximum matchings, likely modulo something implicit. | Medium7 | TreeDynamic programming+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Which is NextGiven a binary tree's numeric identifier under a bijective encoding, compute the identifier of the next tree in a defined ordering among same-size trees, wrapping around if it is the largest. | Medium7 | RecursionMath+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Mitochondrial EveGiven birth and death events tracking maternal lineage and some sequenced mitochondrial DNA samples, determine whether all currently living individuals must share, might share, or must not share the same mitochondrial DNA. | Medium7 | Union-findTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Castle GuardsGiven a recursively described tree of small buildings connected by corridors, compute the minimum vertex cover (guard placement) that watches every corridor in the whole castle. | Medium7 | Dynamic programmingTree+2 | No attempts yet | 2s | 128 MB | Judgeable |
| MobileGiven a recursively nested mobile of weighted objects, find the minimum number of object weights to change so every rod balances left and right. | Medium7 | TreeDynamic programming+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Network MessReconstruct a tree with given leaf-to-leaf distances and output the degrees of internal switch nodes in ascending order. | Medium7 | TreeGraph+2 | No attempts yet | 3s | 128 MB | Judgeable |
| Last Minute ConstructionsGiven a forest of undirected roads plus a set of directed tunnels that must all be used, decide whether a simple path exists from a start to an end village that uses exactly those tunnels. | Medium7 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| MobileGiven a full binary tree of rods and toys, find the minimum number of left-right child swaps so that all toys sit at depths differing by at most 1, with deeper toys to the left. | Medium7 | TreeGreedy+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Family FortuneChoose K nodes in a rooted tree, no one an ancestor of another, maximizing the sum of weights; print 0 if impossible. | Medium7 | Dynamic programmingTree+1 | No attempts yet | 10s | 128 MB | Judgeable |
| Preorder and PostorderCount how many m-ary trees share the given pre-order and post-order traversals. | Medium7 | TreeDynamic programming+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Tournament BracketsGiven team pairings listed in column-major order and the champion, reconstruct the tournament bracket and render it with slashes, backslashes, and underscores. | Medium7 | ImplementationSimulation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Trie, Again TrieGiven trees encoded in preorder, find the repeated subtree whose replacement by one shared copy saves the most nodes, breaking ties by size then preorder. | Medium7 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| MobilesGiven a mobile tree with one unknown object weight, find the weight that balances every bar and check that no two bars collide when they rotate. | Medium7 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |