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 results1,013 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
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
Love PolygonEach of N people loves exactly one person; rewrite the minimum number of love targets so that everyone ends up in a mutual pair.Hard8GraphGreedy+2No attempts yet2s1024 MBJudgeable
PathsCount simple paths in a vertex-colored graph where every vertex on the path has a distinct color, counting both directions separately.Hard8GraphDFS+2No attempts yet3s1024 MBJudgeable
Pineapple FarmingOn a grid of heights with all outside cells treated as height 0, find the largest connected set of cells that forms a puddle bounded by strictly taller neighbors for some threshold h.Hard8Union-findBFS+2No attempts yet2s256 MBJudgeable
Office RelocationGiven a weighted tree with marked query and leaf-coloured vertices, compute for every marked vertex the sum of squared weighted distances to coloured leaves (mod a prime).Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Ttururu TturuCount self-avoiding walks of length 10 on an R x C grid whose cell contents read exactly "ttururu tturu" (the 5-letter chorus "뚜루루뚜루" written row-wise twice).Hard8DFSBrute force+2No attempts yet0.5s512 MBJudgeable
Kingpin EscapeAdd as few edges as possible to a tree with root h so that destroying any one edge still leaves every node connected to h; output the new edges.Hard8TreeGreedy+2No attempts yet2s512 MBJudgeable
TreeChoose exactly m black vertices on a tree so that the maximum distance between any two chosen vertices is as small as possible.Hard8TreeBinary search+2No attempts yet1s512 MBJudgeable
Tree in TreeFor each vertex subset, count the edges in its minimal connecting subtree using Euler tour order and LCA checks.Hard8TreeDFS+2No attempts yet6s512 MBJudgeable
Living SubgraphFind the smallest node set whose induced subgraph is connected and stays connected after deleting any one of its nodes.Hard8GraphBFS+2No attempts yet1s512 MBJudgeable
Katty and WonkiAdd 2 edges to an N-vertex tree to maximize vertices lying on created cycles; return that maximum for the worst case for the tree owner.Hard8TreeGraph+2No attempts yet1s256 MBJudgeable
Colorful TreeMaintain vertex colors on a tree under point updates and answer queries giving the number of edges in the minimal subtree spanning all vertices of one color.Hard8TreeDFS+2No attempts yet5s512 MBJudgeable
Cat DatingIn a rooted tree, each den holds female cats or male cats with a fall limit; count the maximum number of female-male pairs where a male can reach a female downward within the distance limit.Hard8DFSGreedy+2No attempts yet4s1024 MBJudgeable
Graph and QueriesMaintain an undirected graph under edge insertions and deletions, answering connectivity queries between two vertices after each update.Hard8GraphUnion-find+2No attempts yet2s512 MBJudgeable
Tree and Queries 12Maintain a forest under edge insertions and deletions, and answer connectivity queries between two vertices.Hard8TreeUnion-find+2No attempts yet2s512 MBJudgeable
3-SAT 2Given a 3-CNF formula with N variables and M clauses, decide whether it is satisfiable and, if so, output a satisfying assignment.Hard8GraphDFS+2No attempts yet2s512 MBJudgeable
Cow LandOn a weighted tree, support point value updates and path XOR queries between any two nodes, returning the XOR of enjoyment values along the unique route.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Dynamic CentroidFor each prefix tree formed by vertices 1..k, output the smallest centroid (the vertex whose removal leaves components of size at most k/2).Hard8TreeDFS+2No attempts yet1.5s512 MBJudgeable
The Valley OverflowsGiven a tree of valleys with heights, decide whether water starting from any non-K valley can reach valley K under the splash-up movement rule.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
Ali's TypewriterGiven a keypress sequence that builds strings in a buffer and prints them, answer queries counting how often printed string x occurs inside printed string y.Hard8StringTrie+2No attempts yet1s512 MBJudgeable
Overflowing BanknotesFor each query, after updating one node, find the maximum banknotes that can be gathered at one safe when any node is chosen as root and the coins fall optimally.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
kdh9949Find the longest path in an undirected graph whose vertex labels spell repeated KDH blocks, or report -1 if such a path can be infinite.Hard8GraphDynamic programming+2No attempts yet1s1024 MBJudgeable
Tree Colors and QueriesA rooted tree where edges are deleted over time; after each deletion, count distinct colors among vertices still reachable from a queried vertex.Hard8DFSTree+2No attempts yet2s256 MBJudgeable
Expression TreeGiven a binary expression tree with + and - operators, permute the operand values freely to maximize the evaluated result.Hard8TreeGreedy+2No attempts yet1s256 MBJudgeable
Black StonesGiven a tree with some vertices marked black, count how many queries (i, j) admit a connected subtree with exactly i vertices and j black vertices.Hard8TreeDynamic programming+2No attempts yet1s512 MBJudgeable
SpyGiven a subordinate subtree for every leader in two rooted trees of N employees, count for each IOI employee how many of the M spy projects succeed, where spy b succeeds when the matching JOI employee lies in research project b's subtree.Hard8TreeDFS+2No attempts yet2s256 MBJudgeable
White Day Present ExchangeEach student gives treats to one other student; choose whether each makes cookies or cake to maximize total happiness from what they receive.Hard8GraphDynamic programming+2No attempts yet1s256 MBJudgeable
Inquiry IIGiven a connected simple graph with at most n+15 edges, output the size of its maximum independent set.Hard8TreeDFS+2No attempts yet5s512 MBJudgeable
Grand Central StationGiven a tree, find the minimum number of distinct map designs (rooted drawings) such that every vertex can be the center of one design after relabeling.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
DžumbusGiven a forest of N friends with drink thresholds, and Q queries each supplying a total drink S, find the maximum number of people who exchange solutions.Hard8Dynamic programmingTree+2No attempts yet1s512 MBJudgeable
Tree HuggingGiven 2(n-1) edges on n points, decide whether they can be split into a left-rooted increasing tree and a right-rooted decreasing tree, and output one such labeling.Hard8GraphGreedy+2No attempts yet2s512 MBJudgeable
Game on a TreeAlice places a chip on a white node of a rooted tree, then players alternately move it to an unvisited ancestor or descendant, blackening that node; the player who cannot move loses. Determine the winner.Hard8TreeGame theory+2No attempts yet1s256 MBJudgeable
EquilibriumGiven a tree, order its vertices to minimize the sum over vertices of the absolute difference between neighbors placed after and before them.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
Great GDPGiven a vertex-weighted tree and a value and weight per node, find the connected subtree containing the root that maximizes total value divided by total weight.Hard8Binary searchGreedy+2No attempts yet1s512 MBJudgeable
Jumping PathGiven a rooted tree with labels, find the length of the longest ancestor chain with nondecreasing labels, and count how many such chains of that length exist modulo 11092019.Hard8Dynamic programmingDFS+2No attempts yet10s512 MBJudgeable
Water Tanks of Seongdae CountryA tree of water tanks rooted at a capital. Adding water at city A adds 1,2,3,... along the root-to-A path. Answer queries about how much water a given city currently holds.Hard8TreeDFS+2No attempts yet1s256 MBJudgeable
Bird WatchingGiven a digraph P known to contain the true edge set G plus some path-shortcut edges, list all in-neighbors a of T such that every path from a to T uses the edge (a, T).Hard8GraphDFS+2No attempts yet3s512 MBJudgeable
Cave PaintingsCount modulo 1e9+7 the ways to fill empty cells of a bordered grid with water so that any lower-or-equal empty/water region reachable from a water cell is also water.Hard8GraphDFS+2No attempts yet2s512 MBJudgeable
Free EdgesGiven an undirected graph, find the minimum number of edges to paint black so that repeatedly blackening a white edge incident to a vertex with exactly one white edge turns every edge black.Hard8GraphDFS+2No attempts yet1s512 MBJudgeable
The Older We Are, The Worse It HurtsRoot the tree anywhere and order each node's children so that the weighted sum of DFS discovery times is minimized; output that minimum.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Road NetworkGiven a tree, add one edge so that the number of bridges in the resulting graph is minimized, and report that minimum count.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Awesome ShawarmaGiven a tree, count the unordered pairs of nodes whose added edge leaves the number of bridges in [L, R].Hard8TreeDFS+2No attempts yet14s512 MBJudgeable
Tree HullMaintain a set of tree vertices under insertions and deletions, and after each query report the total edge weight of the minimal subtree spanning the current set.Hard8TreeDFS+2No attempts yet3s256 MBJudgeable
Matching In MultiplicationGiven a bipartite graph where each of the n vertices on one side has degree 2, sum the products of edge weights over all perfect matchings, modulo 998244353.Hard8GraphMath+2No attempts yet1s512 MBJudgeable
Remove the TreeGiven a tree, repeatedly delete the vertices of any chosen path (and incident edges); find the minimum number of path-deletions needed to remove every edge.Hard8TreeGreedy+2No attempts yet2s256 MBJudgeable
Hokusai ArtworksOn a directed graph, each city has a museum open only on even days; find the maximum total weight of distinct museums visitable starting at city 0 on an even day.Hard8GraphDynamic programming+2No attempts yet1s512 MBJudgeable
MonkeysChoose K vertices of a tree and delete edges so every chosen monkey can reach another, minimizing the number of surviving edges.Hard8TreeDynamic programming+2No attempts yet4s512 MBJudgeable
Cleaning RobotsCount the ways to partition all vertices of a tree into vertex-disjoint paths such that no two paths can be merged into a longer path.Hard8TreeDynamic programming+2No attempts yet1s512 MBJudgeable
Antennas On TreeFind the smallest set of tree vertices whose distance vectors distinguish every vertex from every other vertex.Hard8TreeDFS+2No attempts yet2s256 MBJudgeable
Delivering FlyersOn a unit-weight tree, find the shortest closed walk from S that covers every node, given the rider can cover all nodes within distance D from any single stop.Hard8TreeGreedy+2No attempts yet1s1024 MBJudgeable
Second Diameter of a TreeGiven a weighted tree with up to 100,000 vertices, find the distance of the second farthest pair of vertices, allowing a tie with the diameter.Hard8TreeDFS+2No attempts yet1s1024 MBJudgeable
Internet ProblemGiven a directed graph, find all vertices lying on every walk from 1 to n, and only on walks from 1 to n, so a walk passes through each chosen vertex exactly once.Hard8GraphDFS+2No attempts yet5s512 MBJudgeable
Roadside AdvertisementsOn a weighted tree, for each of Q queries with five distinct nodes, find the total weight of every edge lying on some shortest path between a pair of the five.Hard8TreeGraph+2No attempts yet1s512 MBJudgeable
Rock ClimbingFind the smallest K such that every K-subset of N rocks contains two rocks A, B with A reachable from B by a strictly upward chain of moves, each move bounded by the max slippery rate.Hard8GraphGreedy+2No attempts yet1s512 MBJudgeable
Similar ArraysGiven pairs of positions, decide whether there is an array with all distinct values and an array with a repeated value that agree on every listed comparison, and output both arrays.Hard8GraphDFS+2No attempts yet1s512 MBJudgeable
Pandemic 2On a weighted tree where some vertices start infected and the infection spreads along edges at speed one, find the maximum number of uninfected connected components that ever exist at one moment.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
StationsLabel the stations of a tree so that a station holding a packet can pick the correct next hop knowing only its own label, the target label, and its neighbours' labels.Hard8TreeDFS+2No attempts yet20s1024 MBJudgeable
Cactus Graph AutomorphismsCount automorphisms modulo 1e9+3 of a given vertex cactus graph with up to 200 vertices.Hard9TreeCombinatorics+2No attempts yet2s128 MBJudgeable
Diameter of a CactusGiven a cactus graph (each edge in at most one cycle), compute the maximum shortest-path distance between any two vertices.Hard9GraphDFS+2No attempts yet1s128 MBJudgeable
WoodpeckersCount ways to place N woodpeckers into two height-ordered trees so every visiting pair lands in different trees and their connecting segments never cross, modulo K.Hard9TreeGraph+2No attempts yet10s128 MBJudgeable
MoleGiven a tree, remove one edge and add one edge (keeping it connected) to minimize the tree's diameter, and output the resulting diameter with the edges swapped.Hard9TreeGraph+2No attempts yet1s128 MBJudgeable
Gates of LogicParse an ASCII-art diagram of logic gates and wires with grid tracing rules (junctions, crossings, negation, ports) and compute values propagated to every named output.Hard9SimulationGraph+2No attempts yet1s128 MBJudgeable
Fool's GameSimulate the full two-player card game 'Fool' with optimal play from both sides and determine which player ultimately wins.Hard9Game theoryDFS+2No attempts yet1s128 MBJudgeable
Room AssignmentsGiven n-1 inventors' two-choice coins forming a graph, pick an edge for the organizer's own coin that maximizes his expected room rating while keeping a perfect assignment possible.Hard9GraphUnion-find+1No attempts yet1s128 MBJudgeable
The Moon of ValenciaGiven a map of places with satisfaction values and walking edges, decide for each query whether a simple path between two nodes exists that fits a time budget and yields a satisfaction sum within 0.1 of a target.Hard9BacktrackingDFS+1No attempts yet1s128 MBJudgeable
OutsourcingGiven two directed labeled graphs (factories) with start and final nodes, decide whether the two sets of label sequences realizable as paths from start to final are identical.Hard9GraphDFS+2No attempts yet1s128 MBJudgeable
IdeasFor each directed tube, find the smallest set of ideas a packet must carry while traversing it so that every reachable person still receives all ideas they need.Hard9GraphDFS+2No attempts yet1s128 MBJudgeable
Congruent Partition of ChocolateGiven a connected polyomino of at most 36 unit squares, decide whether it splits into two connected pieces that are congruent under rotation, reflection, and translation.Hard9Brute forceDFS+2No attempts yet30s128 MBJudgeable
Winmine (Minesweeper)Count the ways to place the remaining mines on the unrevealed squares so that every revealed number matches its adjacent mine count, modulo 1000003.Hard9Dynamic programmingGraph+2No attempts yet2s512 MBJudgeable
The Herbalists' VillageGiven a friendship graph, decide whether it has a planar straight-line drawing where every vertex reaches infinity without crossing an edge.Hard9GraphGeometry+2No attempts yet1s128 MBJudgeable
Longest Paths in a TreeA rooted tree has weighted edges. Handle point updates to edge weights and queries that ask for the maximum-weight downward path from a vertex inside its subtree.Hard9TreeSegment tree+2No attempts yet5s1024 MBJudgeable
King's QuestFor each son, list every girl he likes such that a perfect matching still exists when he marries her.Hard9GraphDFS+2No attempts yet1s128 MBJudgeable
Wandering Flea TrainersGiven two functional graphs on n labeled nodes, decide whether some vertex relabeling makes the graphs isomorphic, i.e. the fleas' dance is identical.Hard9GraphDFS+2No attempts yet3s128 MBJudgeable
MessengersGiven a 2-connected graph, output the lexicographically smallest pair of search plans from city 1 so that for any single occupied non-capital city, both messengers together warn every city.Hard9GraphDFS+2No attempts yet1s128 MBJudgeable
GarbageEach street needs its state flipped or not; a route is a simple cycle, and driving a street flips it. Find the minimum total length of cycles whose symmetric difference equals the set of streets needing a flip.Hard9GraphDFS+2No attempts yet1s128 MBJudgeable
Milk MultidrinkDecide whether a tree with n nodes has a Hamiltonian path from 1 to n where consecutive vertices stay within distance two.Hard9TreeDFS+2No attempts yet1s128 MBJudgeable
Hard ChoiceAfter streets are closed one by one offline, answer for each query whether two edge-disjoint paths still connect the given pair of junctions.Hard9GraphDFS+2No attempts yet5s128 MBJudgeable
HighwaysGiven a tree plus extra highway edges, count for each query (x,y) the main tree path plus alternative single-highway paths that touch the main path only at x and y.Hard9TreeDFS+2No attempts yet3s128 MBJudgeable
It Takes a VillageProcess online trading-post additions that spread through biconnected blocks and capital dominators, and answer revenue queries for single villages.Hard9GraphDFS+2No attempts yet20s128 MBJudgeable
Bulb PuzzleYou rotate every elbow and straight wire so all wires form one path that joins the two bulbs, and print the smallest such layout.Hard9GraphBacktracking+1No attempts yet1s256 MBJudgeable
King GameOn a small board with burned squares, two players alternately move a king to an unvisited neighboring square; report who wins under optimal play.Hard9Game theoryGraph+2No attempts yet5s512 MBJudgeable
Growing a Binary TreeFor each tree, pick a root and count the fewest vertices to add so that the result becomes a complete binary tree (every internal vertex has exactly two children, all leaves equidistant from the root), minimizing that count and then the vertex index; output the count mod 1e9+7.Hard9TreeDFS+2No attempts yet4s512 MBJudgeable
Tree TransformationCount the minimum-size sets of edges whose removal splits the tree into components of power-of-two sizes, modulo 1e9+7.Hard9TreeDynamic programming+2No attempts yet1s512 MBJudgeable
Trees and Queries 10Given a tree with vertex weights, answer path maximum-subarray-sum queries and path range-assign-weight updates.Hard9Segment treeTree+2No attempts yet2s512 MBJudgeable
Lowest common ancestor in a dynamic forestMaintain a forest of rooted trees under link, cut, and lowest-common-ancestor queries, printing each LCA.Hard9TreeLinked list+2No attempts yet2s512 MBJudgeable
Cactus giftIn a cactus graph with up to 4000 vertices, count directed simple paths of each length 1 to N, modulo 1e9+7.Hard9Dynamic programmingTree+2No attempts yet1.5s512 MBJudgeable
Bracket PathsGiven a tree with '(' or ')' on each node, count ordered pairs (a,b) whose path string w_{a,b} is a properly matched bracket expression.Hard9TreeDivide and conquer+2No attempts yet3s1024 MBJudgeable
Creating Fake NewsFind one story vector satisfying n linear equations, then the minimum number of starting people whose reach covers all n people.Hard9MathGraph+1No attempts yet2s512 MBJudgeable
Good triples of pathsCount triples of simple paths in a tree that are either node-disjoint or pairwise intersecting, modulo 1e9+7.Hard9CombinatoricsTree+2No attempts yet2s512 MBJudgeable
One-Way StreetsGiven an undirected multigraph and required reachable pairs, decide for each edge whether every valid orientation matches the input direction (R), the reverse (L), or both are possible (B).Hard9GraphDFS+2No attempts yet3s256 MBJudgeable
Laminar FamilyGiven an undirected tree and f vertex sets, each a simple path, decide whether the family of paths is laminar.Hard9TreeDFS+2No attempts yet2s512 MBJudgeable
Secret AgentGiven a planar straight-line graph (castle walls) where crossing a wall costs its height, find the minimum cost to travel between successive query points, starting from infinity.Hard9GraphGeometry+2No attempts yet2s512 MBJudgeable
Counting CyclesA connected undirected graph with n vertices and at most n+15 edges is given; count all simple cycles, where a simple cycle is a connected subgraph with every degree exactly two.Hard9GraphDFS+2No attempts yet4s512 MBJudgeable
Revenge of the Broken DoorAn adversary hides one edge under construction; the traveler learns about an edge only upon reaching its endpoint and must minimize the worst-case distance from S to T.Hard9GraphShortest path+2No attempts yet10s512 MBJudgeable
Tree EscapeOn a rooted tree where each leaf starts with one piece, players alternately move a piece to its parent and remove it at the root; decide if the first player wins.Hard9Game theoryTree+2No attempts yet2s512 MBJudgeable
Octoppang CountryGiven a connected unweighted graph with K infected vertices and threshold T, compute for every vertex the number of uninfected vertices left when it is deleted and each component with at least T infected vertices spreads infection fully.Hard9TreeDFS+2No attempts yet1s1024 MBJudgeable
Prime Tree - 7Relabel the vertices of each given tree with 1..n so that the number of edges whose endpoints share a common divisor above 1 is minimized, and submit the answer file.Hard9GreedyNumber theory+2No attempts yet10s512 MBJudgeable
Youngkwail Club RoomCover all '.' cells of a grid with 1x1 and 1x2 tiles, avoiding 'X' pillars, using the fewest tiles possible.Hard9GraphDFS+2No attempts yet1s256 MBJudgeable