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 |
|---|---|---|---|---|---|---|
| UnfriendCount the subsets of nodes in a rooted tree that can be removed, where removing a node forces removal of all its descendants. | Easy2 | TreeBrute force+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Huffman TreeGiven Z characters and arity N, decode the stored digit string into the per-character encoding. | Easy2 | TreeString+1 | No attempts yet | 3s | 128 MB | Judgeable |
| ICPC CalculatorEvaluate a dot-indented prefix expression where + sums its operands and * multiplies them. | Easy2 | RecursionTree+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Leaf Nodes in a TreeGiven a tree by parent array, delete a node and all its descendants, then count how many leaf nodes remain. | Easy3 | TreeDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Tree TraversalBuild a binary tree from parent-child input and print its preorder, inorder, and postorder traversals. | Easy3 | TreeDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Kinship DistanceGiven a family forest of parent-child edges, find the shortest kinship distance between two given people or output -1 if unconnected. | Easy3 | GraphBFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| The Leisurely StrollGiven a rooted tree of choice-nodes where leaf edges lead to pastures, find the maximum number of edges on any root-to-pasture path. | Easy3 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| S-TreesGiven an S-tree's variable ordering and terminal labels, evaluate the Boolean function for each supplied variable assignment. | Easy3 | TreeSimulation+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Help the problem setterFor each test case, read a binary search tree on labels 1..n and print each node's frequency, computed bottom-up as 1 plus the sum of the frequencies of all its proper descendants. | Easy3 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Computation of a Road Network PlanGiven the number of cities n and a target diameter d, print a specific tree: a path of length d with all remaining cities hung off its middle vertex. | Easy3 | TreeImplementation+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Network InvestmentFind the tree edge whose removal maximizes the product of the two component sizes. | Easy3 | DFSTree | No attempts yet | 1s | 128 MB | Judgeable |
| Candy FactoryEach parent in a heap-ordered binary tree makes as many candies as the smaller child count, and the total subtracts consumed ingredients from all made candies. | Easy3 | TreeRecursion+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Cracking Tree CodesGiven a tree and its leaf-stripping code with some entries erased, the program replays the encoding to recover the missing numbers. | Easy3 | SimulationTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Complete Binary TreeReconstruct each level of a complete binary tree from its inorder visit order. | Easy3 | TreeRecursion | No attempts yet | 1s | 128 MB | Judgeable |
| Hyacinth frequency assignmentAssign one frequency to each edge of a tree by the stated DFS rule so each node uses at most two frequencies. | Easy3 | TreeDFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Neurotic NetworkEvaluate the weighted sum from the leaves to the root of a tree and print FREAK OUT for an even result, else the value modulo 1,000,000,007. | Easy3 | TreeDynamic programming+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Finding Parents in a TreeStarting from node 1 as the root, print the parent of every other node in the given tree. | Easy3 | BFSTree | No attempts yet | 1s | 256 MB | Judgeable |
| Orienting Molecular BondsDirect every tree edge from the endpoint at even distance from node 1 to the one at odd distance. | Easy3 | BFSTree | No attempts yet | 1s | 64 MB | Judgeable |
| Modern Art Plagiarism (Small)Decide whether the smaller tree is a connected subgraph of the larger tree, with only the shapes mattering, not the original labels. | Easy3 | TreeBacktracking | No attempts yet | 5s | 512 MB | Judgeable |
| Largest Common Vertex on a Rooted TreeFor two nodes in a complete binary tree numbered heap-style, find the deepest common ancestor k and print 10k. | Easy3 | TreeMath+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Binary treeGiven each node's parent in a binary tree with n up to 20, print the height (distance from the root) of every node. | Easy3 | TreeDFS | No attempts yet | 2s | 512 MB | Judgeable |
| Trees and QueriesCount the vertices in the subtree of each queried node in a tree with a given root. | Easy3 | TreeDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Binary Search TreeInsert a sequence of integers into a BST and output the depth of each inserted node. | Easy3 | TreeRecursion+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Thread TreeGiven n posts where each post names its parent post, print the messages in preorder with dots showing each post's depth. | Easy3 | TreeDFS+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Distance Between Tree NodesGiven a weighted tree and multiple node pairs, compute the path distance between each pair using tree traversal. | Medium4 | TreeBFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Diameter of a TreeGiven a weighted tree of up to 10,000 nodes rooted at node 1, compute the maximum-length path between any two nodes. | Medium4 | TreeDFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Maximum Independent Set in a TreeGiven a weighted tree, compute a maximum weight independent set using tree DP and output the chosen vertices. | Medium4 | Dynamic programmingTree+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Nearest Common AncestorGiven a rooted tree and two nodes, find their nearest common ancestor for each test case. | Medium4 | TreeDFS+1 | No attempts yet | 1s | 128 MB | Judgeable |
| TreeGiven the preorder and inorder traversals of a binary tree, reconstruct the tree and print its postorder traversal. | Medium4 | TreeRecursion+1 | No attempts yet | 1s | 192 MB | Judgeable |
| Relative RelativesGiven Ted's age of 100 and each descendant's father name plus the father's age at the child's birth, compute every descendant's age and list them oldest first, ties broken by name. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Tree GraftingGiven a depth-first traversal string of an ordered tree, report its height and the height after converting it to a left-child/right-sibling binary tree. | Medium4 | TreeStack+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Prefix CodesDecode several binary messages with a prefix code given as a heap-indexed tree string, where a bit 0 or 1 walks to a child until a leaf symbol is reached. | Medium4 | TreeImplementation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Meeting PlaceGiven a rooted tree and M queries, report the lowest common ancestor of two nodes for each query. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Clear Cold WaterGiven a rooted binary tree described by branch points, print the distance from the barn to the endpoint of every pipe. | Medium4 | TreeBFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Is It a Tree?For each test case, read directed edges until a pair of zeros and decide whether the graph is a tree under the three given conditions, printing the case number and verdict. | Medium4 | GraphUnion-find+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Tree RecoveryGiven a binary tree's preorder and inorder traversal strings, print its postorder traversal. Process runs until end of file. | Medium4 | TreeRecursion+1 | No attempts yet | 1s | 128 MB | Judgeable |
| From Prefix to PostfixTranslate each prefix arithmetic expression over + and - into its equivalent postfix form, stopping at the terminating 0. | Medium4 | StackTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Packet RoutingGiven a tree with weighted edges connecting N computers, compute the travel time along the unique path between each query pair of computers. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Christmas Tree OrnamentA tree of N lamps is built incrementally and recolored M times; after each recolor, report how many edges join two lamps of equal color. | Medium4 | TreeImplementation | No attempts yet | 1s | 1024 MB | Judgeable |
| Holiday GiftsAssign one of two priced gifts to each node of a rooted tree so no two adjacent employees share a gift, minimizing total cost. | Medium4 | TreeDynamic programming+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Handong the Salesman!Given a tree, start at node 1 and visit m listed nodes in order, summing the tree distances between consecutive stops. | Medium4 | GraphTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| DyzioParse a 0/1 description of recursive halving cuts and output the cut count at which the first shortest piece appears. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| MegavirusGiven k and n viruses from generation k in a binary tree, find the deepest generation whose node is an ancestor of all given viruses. | Medium4 | TreeBit manipulation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| MerchantFind the simple path, possibly empty, in a weighted tree whose edge weights sum to the largest value. | Medium4 | TreeDynamic programming+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Quad TreesBuild the quadtree partition of each binary image and print its level-order bitstream as uppercase hex without leading zeros. | Medium4 | Divide and conquerRecursion+2 | No attempts yet | 1s | 128 MB | Judgeable |
| CousinsReconstruct the tree defined by consecutive-number groups and count the cousins of node k. | Medium4 | TreeSimulation | No attempts yet | 3s | 128 MB | Judgeable |
| Tree ColoringCount colorings of an N-node tree with K colors so adjacent nodes differ, modulo 93563. | Medium4 | Dynamic programmingTree+1 | No attempts yet | 1s | 128 MB | Judgeable |
| ClawsCompute each hinge grade from subtree and root-path bar weights and report the largest root-to-claw sum of grades over all claws. | Medium4 | TreeDFS | No attempts yet | 2s | 512 MB | Judgeable |
| Traffic CongestionPick the tree city that minimizes the largest number of fans traveling on any single road when all fans leave the arena city. | Medium4 | TreeDFS | No attempts yet | 3s | 256 MB | Judgeable |
| Turtle ElderPick safe start and end islands in a tree so the sum of values along the path is as large as possible, staying home when the best sum is not positive. | Medium4 | TreeDynamic programming | No attempts yet | 5s | 256 MB | Judgeable |
| Switch toggling instructionSimulate trains arriving over time through a binary switch tree and emit the fewest latest possible toggles routing each train to its platform. | Medium4 | SimulationTree | No attempts yet | 2s | 256 MB | Judgeable |
| Binary Mobile WidthCompute the horizontal width of a balanced binary mobile from rod lengths and bead weights using torque balance. | Medium4 | TreeDFS | No attempts yet | 1s | 256 MB | Judgeable |
| NetworkAdd the fewest edges to a tree so it stays connected after any single edge breaks, pairing leaves in the prescribed DFS order. | Medium4 | TreeDFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Lowest Common AncestorGiven a rooted tree, answer each query with the number of the deepest vertex that is an ancestor of both given vertices. | Medium4 | TreeDFS | No attempts yet | 3s | 256 MB | Judgeable |
| Lowest Common Ancestor 2Given a rooted tree with up to 100,000 nodes, answer up to 100,000 lowest common ancestor queries. | Medium4 | TreeDFS | No attempts yet | 1.5s | 256 MB | Judgeable |
| Rational Number Tree (Small)Given the level-order listing of the rational number tree, find the n-th fraction and the position of a given fraction. | Medium4 | TreeBFS+1 | No attempts yet | 5s | 512 MB | Judgeable |
| Decision TreeParse a recursively defined decision tree, then for each animal walk the tree using its features and multiply node weights to get the probability. | Medium4 | TreeRecursion+2 | No attempts yet | 5s | 512 MB | Judgeable |
| Ceiling FunctionInsert each prototype's values into a binary search tree in order, then count how many distinct tree shapes appear across the prototypes. | Medium4 | TreeImplementation+1 | No attempts yet | 5s | 512 MB | Judgeable |
| Road Network of a Perfect Binary TreeFind the minimum number of cars whose vertex-disjoint paths cover every vertex of a perfect binary tree of height H exactly once. | Medium4 | TreeDynamic programming+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Scrooge MinhoGiven a tree, place one fire station at the vertex minimizing the maximum distance to any other vertex, and output that distance. | Medium4 | TreeGraph+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Tree and paths of length twoDecide whether some tree on N nodes has exactly S simple paths of length 2. | Medium4 | TreeCombinatorics+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Rational SequenceGiven p/q, find its index in the breadth-first ordering of the Calkin-Wilf tree, where each node p/q has children p/(p+q) and (p+q)/q. | Medium4 | MathNumber theory+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Far Far AwayGiven a directed tree rooted at city 1 with weighted edges, find the maximum root-to-node path weight, or -1 if it stays below M. | Medium4 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| DragsterGiven pairwise win probabilities and a binary elimination bracket, compute the probability that driver 1 wins the tournament. | Medium4 | ProbabilityTree+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Obfuscated TreesDecode a tree from its obfuscated token stream, where each internal node carries an ordering code and subtree count, then print its values in pre-order. | Medium4 | TreeRecursion+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Build a treeConstruct a tree on n nodes with exactly m leaves whose sorted edge list is lexicographically smallest, and print its n-1 edges. | Medium4 | TreeGreedy+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Company culture 1Given each employee's manager and a list of praises, propagate every praise value down the whole subtree and print the total each employee receives. | Medium4 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Cut Vertices and BridgesGiven a tree with N vertices and queries, report for each query whether a specified vertex is a cut vertex or a specified edge is a bridge. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Grass PlantingGiven a tree with N fields, plant grass so that no two fields at distance one or two share a type, and output the minimum number of types needed. | Medium4 | TreeGreedy+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Milk FactoryGiven a directed tree on N nodes, find the smallest node reachable from every other node, or output -1 if none exists. | Medium4 | GraphDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Road ConstructionGiven a tree with n countries and weighted edges, sum over all edges of weight times the absolute difference in size of the two components the edge splits the tree into. | Medium4 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| I Will Be Your Bridge!A tree lost one edge, splitting it into two components. Print any pair of islands, one from each component, that reconnects the tree. | Medium4 | GraphDFS+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Gugu the RaccoonGiven a weighted tree rooted at node 1, find the maximum distance from node 1 to any other node. | Medium4 | TreeDFS+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| CocktailGiven a tree of N ingredients linked by N-1 known mass ratios, compute the smallest positive integer masses that satisfy every ratio. | Medium5 | TreeDFS+2 | No attempts yet | 2s | 128 MB | Judgeable |
| PrefixGiven up to 50 words, find the largest subset where no word is a prefix of another, using a trie and tree DP. | Medium5 | TrieDynamic programming+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Tree DiameterGiven a weighted tree with up to 100,000 vertices, compute the diameter as the maximum distance between any two vertices. | Medium5 | TreeDFS+2 | No attempts yet | 2s | 256 MB | Judgeable |
| Roads of the Northern CountryGiven the edges of a weighted tree of up to 10,000 cities, compute the length of the tree's diameter (the longest path between two nodes). | Medium5 | TreeGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| New Year PartyPick a maximum-score guest list from a company tree so no employee and their direct manager both attend, computed with and without the root. | Medium5 | Dynamic programmingTree+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Distance Between VerticesGiven a weighted tree with up to 40,000 nodes, answer up to 10,000 queries about the path distance between two vertices, requiring an LCA-based approach for efficiency. | Medium5 | TreeBinary search+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Bug on a TreeGiven a tree with fruit values on vertices, find the maximum sum path (simple path) and its smallest-numbered starting endpoint. | Medium5 | TreeDynamic programming+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Tree Height and WidthGiven a binary tree's parent-child structure, place nodes on a grid by binary tree layout rules and find the level with the maximum column width, breaking ties by smallest level. | Medium5 | TreeBFS+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Recover Tree PreorderGiven a tree's inorder and postorder sequences, reconstruct the tree and output its preorder traversal. | Medium5 | TreeRecursion+1 | No attempts yet | 5s | 128 MB | Judgeable |
| Tree CuttingGiven a tree with n vertices, find the minimum number of edges to cut so some resulting piece has exactly m vertices, or report impossibility. | Medium5 | TreeDynamic programming+1 | No attempts yet | 2s | 128 MB | Judgeable |
| GemsGiven a tree, assign positive integer prices to vertices so adjacent vertices differ, minimizing total sum, essentially a greedy coloring based on tree structure. | Medium5 | TreeGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| LabyrinthGiven a grid maze that forms a tree of free cells, compute the diameter (longest path in number of steps) between any two free cells. | Medium5 | GraphBFS+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Kingdom RoadmapGiven a tree, compute the minimum number of extra edges needed so the graph stays connected after any single edge removal, which equals the number of leaves divided by two, rounded up. | Medium5 | TreeGraph+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Family TreeGiven a tree where each node lists its single child (parent-of relation), compute the minimum number of extra ancestor nodes to insert so no node has more than d parents. | Medium5 | TreeGreedy+1 | No attempts yet | 2s | 64 MB | Judgeable |
| GodfatherGiven an undirected tree, find all vertices that minimize the largest connected component size after removal (the tree centroid(s)). | Medium5 | TreeDFS+1 | No attempts yet | 2s | 64 MB | Judgeable |
| Pathological PathsGiven a set of file paths defining a directory tree, resolve query paths (with '.', '..', and index.html shortcuts) and decide if two paths refer to the same existing file. | Medium5 | StringHash map+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Router Placement to Minimize Maximum TTLGiven a tree, pick the vertex that minimizes the largest distance to any other vertex, and output that minimum maximum distance (the tree's radius). | Medium5 | TreeGraph+2 | No attempts yet | 1s | 128 MB | Judgeable |
| CaterpillarGiven up to 100 nodes, decide whether the graph is a connected tree whose every node lies on or adjacent to some single path. | Medium5 | GraphDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Genealogical ResearchProcess birth and death records, then answer ancestor and descendant queries by printing the family tree recursively with dates. | Medium5 | RecursionTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Mobiles AlabamaParse a nested mobile description and compute, for each bar, the tie point that balances the weights hanging from its two sides. | Medium5 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Normal FormEvaluate a fully parenthesized AND/OR tree where odd levels are AND and even levels are OR, for several long test cases. | Medium5 | TreeImplementation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Road TripGiven a weighted tree rooted at city 1, remove exactly one non-root vertex so the round trip from city 1 covering all remaining cities is shortest, and report that length. | Medium5 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Pasture WalkingGiven a weighted tree with N vertices and Q queries, find the path length between each queried pair of vertices. | Medium5 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Treasure CaveGiven a binary branching from passage 1, find the list of passages on the unique path from the entrance to passage T and its length. | Medium5 | TreeDFS+2 | No attempts yet | 1s | 128 MB | Judgeable |
| EntropyFor each line of text, print the fixed 8-bit ASCII bit length, the optimal prefix-free Huffman bit length, and the compression ratio rounded to one decimal. | Medium5 | GreedyHeap+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Code the TreeParse a parenthesized tree description, then repeatedly remove the smallest-numbered leaf and print its neighbor to build the Prufer code. | Medium5 | TreeImplementation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Decode the TreeGiven a Prüfer code, rebuild the labeled tree on n vertices and print it as a canonical rooted word with children sorted by number. | Medium5 | TreeHeap+2 | No attempts yet | 1s | 128 MB | Judgeable |