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
String PhoneDecide whether each building can post its officer on one of its four corners so that every string length equals the street distance between the pair it joins.Hard8GraphDFSNo attempts yet1s128 MBJudgeable
Disjoint water supplyCount the pairs of cities with paths from city 1 that meet only at city 1 in a pipe network ordered by decreasing altitude.Hard8GraphTopological sort+2No attempts yet1s128 MBJudgeable
The kingdomFollow the fixed DFS, vertex-split, and Euler-circuit steps to output edge-disjoint even-length trails pairing every odd-degree vertex.Hard8GraphDFS+2No attempts yet1s256 MBJudgeable
Recovering the PopulationsGiven a tree and the distance-weighted sums at each node, recover the node weights that produce them.Hard8TreeDFS+1No attempts yet4s256 MBJudgeable
Volunteer CampStarting from each house in a weighted tree, find the shortest truck route that visits K marked houses without driving back.Hard8TreeDynamic programming+1No attempts yet2s128 MBJudgeable
Magical SwitchesChoose which of the 26 color switches to push so a token can walk from the left edge to the right edge of a 3-row board.Hard8GraphDFS+1No attempts yet8s512 MBJudgeable
ToursFind every k for which roads can go to k companies so each cycle contains the same number of roads of each company.Hard8GraphDFS+1No attempts yet3s256 MBJudgeable
Which intersections did I pass?Given a connected undirected graph, each query asks how many vertices lie on some walk from a to b that never revisits the endpoints in the middle.Hard8GraphDFS+1No attempts yet2s256 MBJudgeable
Tree of PainDecide for each small pattern tree whether it embeds into the organization tree with matching labels and ancestry preserved both ways.Hard8TreeDynamic programming+2No attempts yet1s256 MBJudgeable
2-SAT smallest assignmentDecide whether a 2-CNF formula over up to 10000 variables is satisfiable and output the lexicographically smallest satisfying assignment.Hard8GraphDFS+2No attempts yet1s256 MBJudgeable
Seonjin's Frozen KingdomDecide whether a walk on a grid that breaks each cell it leaves can visit the hatch cell, leave it, and step back onto it.Hard8DFSGraphNo attempts yet2s256 MBJudgeable
Juice JunctionsAdd up the maximum unit-capacity flow between every pair of junctions in a graph where each junction joins at most three pipes.Hard8GraphTree+2No attempts yet7s512 MBJudgeable
King's InspectionFind the lexicographically smallest directed tour that starts and ends at city 1 and visits every other city exactly once.Hard8GraphBacktracking+1No attempts yet10s512 MBJudgeable
Routing a Marathon RaceFind a simple path from junction 1 to junction n that minimizes the total personnel cost of the junctions on the path and their direct neighbors.Hard8BacktrackingGraph+2No attempts yet3s256 MBJudgeable
Connect the CellsConnect each color pair with disjoint grid paths that cover every cell and print the lexicographically smallest direction map.Hard8BacktrackingGraph+1No attempts yet3s256 MBJudgeable
SubstringsOrder all given strings as the consecutive length-L windows of one string of length L+N-1 and print the lexicographically smallest such string.Hard8GraphDFS+2No attempts yet2s256 MBJudgeable
Connecting the wiresPlace each equal-number pair above or below a row so same-side joining arcs never cross, and print the lexicographically smallest side string.Hard8GraphDFS+2No attempts yet1s64 MBJudgeable
The Bored Traveling Salesman (Large)Visit every city in a connected graph using paired outbound and return flights so the ZIP codes in order of first visit form the smallest possible number.Hard8DFSGraph+1No attempts yet5s512 MBJudgeable
PoklonGiven a tree of scales, add positive real weights so every scale balances with minimum total added mass, then print the final total mass in binary.Hard8TreeDFS+2No attempts yet1s256 MBJudgeable
Longest RiversGiven a river network tree and source names, find for each name the best rank it can achieve over all valid downstream naming choices.Hard8TreePrefix sum+2No attempts yet10s512 MBJudgeable
Similar SubwaysGiven two trees with up to 50 nodes each, find the largest k such that some connected k-node subtree of the first is isomorphic to some connected k-node subtree of the second.Hard8TreeDynamic programming+2No attempts yet3s512 MBJudgeable
HyperwaysAfter each edge is added to a multigraph, report how many edges became safe, where an edge is safe when it lies on a cycle.Hard8Union-findGraph+2No attempts yet3s1024 MBJudgeable
A Lot of GamesGiven a trie of strings, play the prefix-building game k times with the loser starting next; report who wins the last game.Hard8TrieGame theory+2No attempts yet2s512 MBJudgeable
Hongjun and the Possible SetsCount the nonempty connected vertex subsets of a weighted tree whose maximum minus minimum weight is at most d.Hard8TreeDFS+2No attempts yet3s512 MBJudgeable
Hongjun and the TreeProcess subtree updates that add a distance-dependent value to each vertex, answering point-weight queries modulo 1e9+7.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Easily Happy TreeDelete the fewest leaves from a rooted tree so that no remaining vertex has a descendant farther away than that descendant's own limit a_u.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
TreeMaintain a rooted tree under vertex deletions (children reparent to grandparent) and answer distance queries between two live vertices.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
TouristsGiven a tree on n nodes, sum the number of nodes on the path from x to y over all pairs where y is a larger multiple of x.Hard8TreeMath+2No attempts yet5s512 MBJudgeable
Cube DividingCount the face-connected components of unit cubes left in an A x B x C box after removing N given cubes, where the box is huge but N is at most 20000.Hard8GraphBFS+2No attempts yet5s512 MBJudgeable
Checkpoint candidatesGiven an undirected graph, a set of source vertices, and a set of airport vertices, count the vertices that every source-to-airport path must pass through.Hard8GraphDFSNo attempts yet2s128 MBJudgeable
Quarantine StationsPlace K quarantine barriers on the edges of a weighted tree so that the largest connected component's total population is minimized.Hard8TreeBinary search+1No attempts yet3s256 MBJudgeable
TreeAfter each query asks whether two vertices are still connected, the tree may lose one edge based on the answer, so connectivity must be tracked under online deletions.Hard8TreeUnion-find+2No attempts yet2s512 MBJudgeable
Two TreesPick a vertex subset connected in both of two trees to maximize the total score, with the empty set allowed.Hard8TreeDFS+1No attempts yet2s512 MBJudgeable
Counting Similar TreesGroup labeled trees that are isomorphic under a bijection preserving edge label differences, and report each group size.Hard8TreeHash map+2No attempts yet2s512 MBJudgeable
Inversions of a simple path sequenceGiven a connected unimodal (unicyclic) graph, find a minimum inversion count over simple paths visiting at least K vertices, or -1 if none exist.Hard8GraphDynamic programming+2No attempts yet2s512 MBJudgeable
Blue vertex distance sums on a treeProcess paint and distance-sum queries on a weighted tree, reporting for each query 2 the total distance from x to all blue vertices.Hard8TreePrefix sum+2No attempts yet5s512 MBJudgeable
Edsger DijkstraGiven a program of labeled print statements and if-goto statements with counters that are true for a bounded number of times, decide whether transforming every if-goto into a do-while loop keeps the program's output and compiles.Hard8SimulationImplementation+2No attempts yet2s256 MBJudgeable
Vertices connected by the same colorProcess color flip and reachability queries on a tree where two vertices are connected if every vertex on their path has the same color.Hard8TreeUnion-find+2No attempts yet2s512 MBJudgeable
VirusGiven a binary tree, find the minimum number of nodes that end up infected when one node may be protected each round.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Dona MinhocaOn a cactus graph, for each query (entry chamber, worm length) decide whether a closed non-backtracking walk of length at most M exists and give the shortest such distance.Hard8GraphDFS+2No attempts yet2s512 MBJudgeable
Ecology PreserveGiven an N by N grid of tree counts, pick a connected set of exactly M cells (M at most 10) maximizing the total tree count.Hard8Dynamic programmingDFS+2No attempts yet2s512 MBJudgeable
Street DetourFor each test, after removing street 1, decide whether the graph stays strongly connected, or becomes so by reversing one-way streets or by making streets two-way.Hard8GraphBFS+1No attempts yet2s512 MBJudgeable
BurzaGiven a tree and a blind pre-committed node-marking order, decide whether the coin can be forced to move fewer than K times regardless of the adversary's play.Hard8Game theoryTree+2No attempts yet1s512 MBJudgeable
Calculating TaxesOn a tree where each house picks a divisor of its income, maximize the total sum of chosen values so that every pair of adjacent houses picks coprime values.Hard8Dynamic programmingTree+2No attempts yet8s512 MBJudgeable
Dictionary GameWords are destroyed by prefix cuts; after each insertion into the dictionary, report which player wins the impartial game under optimal play.Hard8Game theoryTrie+2No attempts yet5s512 MBJudgeable
Sky TaxOn a tree with a moving capital, each vertex answers for all vertices whose path to the capital passes through it; move the capital or query a vertex's count.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
Invisible IntegersGiven up to 10 hints, each a walk order of distinct digits 1 to 9, find the shortest hidden integer sequence that can produce every hint.Hard8BacktrackingDFS+2No attempts yet5s512 MBJudgeable
Binary CodeEach of n binary words has at most one unreadable bit; decide whether the ?s can be filled so no word is a prefix of another.Hard8TrieGreedy+2No attempts yet2s2048 MBJudgeable
Beautiful PathsOn a tree with capitals 1 and 2, sum over all pairs of cities of the minimum distance-to-nearest-capital along their path.Hard8TreeDFS+2No attempts yet1s128 MBJudgeable
Scout GatheringsOn a tree, support adding a member at a city and querying the sum of weighted distances from all members to the current gathering city, which moves along edges.Hard8TreeDFS+2No attempts yet1s128 MBJudgeable
RhymeGiven N distinct words, find the longest sequence using each word at most once where consecutive words rhyme: their longest common suffix has length at least the longer word's length minus one.Hard8StringTrie+2No attempts yet1s256 MBJudgeable
Company Culture 4On a rooted tree, praise spreads downward from an employee to all descendants or upward to all ancestors, the direction flips over time, and queries ask for an employee's accumulated praise.Hard8TreePrefix sum+2No attempts yet2s512 MBJudgeable
WellsOn a tree where placing wells at a vertex counts for it and its direct neighbors, find the minimum number of wells so every village's demand is met.Hard8TreeDynamic programming+2No attempts yet2s256 MBJudgeable
Ski ResortFor each query, count the size-k sets of areas such that every favorite area has exactly one stocked area lying on every path from the top, and all chosen areas lie on paths to favorite areas.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Yeongseon takes the baitOn a tree, count alternating left/right paths from a fixed start where each vertex is used once; report the maximum over all starting vertices.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
Good News and Bad News (Large)Assign a nonzero integer to each directed edge so every vertex's outgoing sum equals its incoming sum, exactly as built by a prescribed DFS cycle-circulation procedure.Hard8GraphDFS+2No attempts yet5s512 MBJudgeable
The Restless CatIn a connected, planar, simple graph with a guaranteed cycle, find rooms whose single-vertex deletion leaves the graph acyclic (a forest), summing their indices.Hard8GraphDFS+1No attempts yet2s512 MBJudgeable
City AttractionsOn a weighted tree, Gigel repeatedly jumps from his current city to the city maximizing a_y - dist(x, y), breaking ties by smallest index, and we must report his position after K days.Hard8TreeDFS+2No attempts yet2s64 MBJudgeable
Tree path decompositionCount the ways to partition all nodes of an unrooted tree into vertex-disjoint paths, where each path's node sum is nonnegative, modulo 1e9+7.Hard8TreeDynamic programming+1No attempts yet2s512 MBJudgeable
Who made the Christmas soundRoot the tree at socket 1 and count colorings with R, G, B bulbs, respecting the green and blue adjacency rules, whose total cost is divisible by K.Hard8Dynamic programmingTree+2No attempts yet1s512 MBJudgeable
Broadcast StationsGiven a tree, assign non-negative integer powers to vertices so every zero-power vertex lies within reach of some positive-power vertex, minimizing the total power. Report that minimum sum.Hard8Dynamic programmingTree+2No attempts yet0.5s512 MBJudgeable
Sheets and PaintballsGiven axis-aligned rectangles and colored points, count the distinct color labels that reach each rectangle along the vertical stacking order.Hard8SortingSegment tree+2No attempts yet2s512 MBJudgeable
Crowd ControlFind the unique maximum-capacity simple path from node 0 to node n-1 and list every other edge incident to a vertex on that path that must be closed.Hard8GraphShortest path+2No attempts yet2s512 MBJudgeable
Hoarse HorsesGiven line segments in the plane, count the maximum number of faces enclosed by them, i.e. bounded regions of their arrangement.Hard8GeometryGraph+2No attempts yet2s512 MBJudgeable
Royal TaxGiven a tree of cities, each with tax gold and a carriage of capacity C, find the minimum total distance to collect all gold into the capital vault.Hard8TreeDynamic programming+2No attempts yet1s1024 MBJudgeable
Keep it coveredDecide whether a grid of dots and empty cells can be tiled by four line-piece types so that lines match across shared sides and never touch the border.Hard8GraphDFS+2No attempts yet1s1024 MBJudgeable
Rainbow RoadsGiven a tree whose edges are colored, find every node v such that all simple paths starting at v have no two consecutive edges of the same color.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Hidden SupervisorsGiven a partial parent array, fill in the missing supervisors to complete a rooted tree and maximize the number of disjoint parent-child pairs.Hard8TreeDynamic programming+2No attempts yet3s512 MBJudgeable
Extra Judicial OperationGiven a connected undirected graph, find the minimum number of vertices beyond one that must hold servers so every vertex still reaches a server after any single edge is removed.Hard8GraphDFS+2No attempts yet2s512 MBJudgeable
Balloon WarehouseSimulate repeated insertions into an infinite balloon line, then report the colors at positions l to r-1 after all instructions.Hard8TreeDFS+2No attempts yet7s512 MBJudgeable
Infinite TreesGiven two possibly infinite trees defined by node-to-children mappings, decide whether their roots have the same ordered structure, where recursive nodes make the unfolding infinite and require comparing regular trees.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
CounterspellsAfter each of n leaf insertions into a rooted tree, find the minimum number of vertex recolorings needed to restore the unique well coloring.Hard8TreeDFS+2No attempts yet1s1024 MBJudgeable
Corporate life after a hostile takeoverGiven two rooted trees on the same n employees, count for each employee how many others are descendants in both trees.Hard8TreeDFS+2No attempts yet0.5s1024 MBJudgeable
MousetrapOn a tree, Dumbo blocks or cleans edges while an edge-averse mouse moves; find the minimum moves to force it into the trap.Hard8TreeDFS+2No attempts yet5s512 MBJudgeable
ChaseJerry walks a simple path in a tree, dropping up to v breadcrumbs that zero out neighbor pigeon counts; maximize the pigeons Tom later meets minus the pigeons Jerry met.Hard8TreeDynamic programming+1No attempts yet4s512 MBJudgeable
Embedding EnumerationCount the ways to place a labeled tree's nodes into a 2 by n grid so node 1 sits at the top-left, edges touch, and no cell repeats, modulo 1e9+7.Hard8TreeDFS+2No attempts yet4s512 MBJudgeable
Hyunsoo CityGiven a connected cactus graph with toggleable edges, answer connectivity queries under edge updates, where each edge lies on at most one cycle.Hard8GraphDFS+2No attempts yet1s512 MBJudgeable
Directing the TreeCount the orientations of a tree's edges such that every given vertex pair has a directed path one way or the other, modulo 1e9+7.Hard8TreeDFS+2No attempts yet2s256 MBJudgeable
Getting Back HomeOn a tree with home at node 1 and office at node n, find the smallest flashlight range d so that a random walk governed by visibility rules always reaches home within 10^9 steps.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
BureaucracySimulate repeatedly sending a task down the smallest-numbered child on each root-to-leaf path, paying 1,2,3,... coins up the chain, and deleting the leaf.Hard8TreeDFS+2No attempts yet1s64 MBJudgeable
Christmas TreeGiven the final colours on a tree after M path-painting updates with distinct colours, reconstruct the unique valid update order and the endpoints of each colour's shortest covering path.Hard8TreeDFS+2No attempts yet0.7s512 MBJudgeable
Cat and MouseOn a tree with distinct edge weights, the mouse always moves to its heaviest incident edge (or second heaviest if the cat blocks it); find the minimum number of mouse moves for the cat to trap it.Hard8TreeDFS+2No attempts yet10s512 MBJudgeable
HH CountryFor each query set of tree vertices, output twice the sum of pairwise tree distances.Hard8TreeDFS+1No attempts yet10s512 MBJudgeable
LCA and queriesFor each query with a designated root r, report the LCA of u and v in a tree of up to 100,000 vertices.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Graph and Minimum Spanning TreeFor each edge of a connected weighted undirected graph, print the weight of a minimum spanning tree that is forced to include that edge.Hard8Minimum spanning treeUnion-find+2No attempts yet2s512 MBJudgeable
City MaintenanceGiven a tree with a price on every vertex, find the maximum, over all choices of a removed vertex, of the sum of the maximum price within each remaining connected component.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Arranging game levelsCount rooted tree arrangements of N levels where each level's clear score S_i and the cumulative score K_i along the root-to-level path are given, and children must have larger S than parents.Hard8TreeCombinatorics+2No attempts yet1s256 MBJudgeable
Tree SeparatorGiven a tree, delete all vertices on some simple path between two chosen vertices; maximize the number of remaining components of size at least K.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Non-redundant DriveIn a tree where each node gives g fuel and each edge costs d, find the longest simple path from any start such that the running fuel never drops below zero, refueling once per node.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Map of the Ninja HouseReconstruct the graph of a ninja house from the counter and door records produced by a fixed DFS exploration, handling back edges, skips, and multi-edges.Hard8GraphDFS+2No attempts yet2s512 MBJudgeable
Äventyr 2On a tree, timelines get marked over time, and after each mark you must report the distance from a queried vertex to the nearest marked vertex.Hard8TreeBFS+2No attempts yet1s256 MBJudgeable
Frogs 2Assign one frog to each pad so that every frog sits on a preferred pad and each log joins two frogs with equal interest in the log's topic.Hard8GraphBacktracking+2No attempts yet1s256 MBJudgeable
Cow at Large (Platinum)In a tree, for each barn find the minimum number of farmers placed at exits needed to catch Bessie, who starts there and runs for the nearest exit at equal speed.Hard8TreeDFS+2No attempts yet4s512 MBJudgeable
Cow at LargeOn a tree of N barns, find the minimum number of farmers placed at exits so they catch Bessie, who starts at node K and runs to any exit.Hard8TreeBFS+1No attempts yet2s512 MBJudgeable
Broken GearboxAssign each of n gear radii to a vertex of a connected graph so that every edge's distance equals the sum of its assigned radii, returning the lexicographically smallest assignment or impossible.Hard8GraphMath+2No attempts yet2s512 MBJudgeable
The CaveOn a tree, decide whether one chamber lies on some walk from a_i to b_i using at most d_i edges, for every speleologist, and output the smallest such chamber.Hard8TreeGraph+2No attempts yet2s512 MBJudgeable
Conquer the WorldArmies sit on the nodes of a weighted tree; move them along edges to satisfy each node's demand while minimizing total transport cost.Hard8TreeDFS+1No attempts yet8s1024 MBJudgeable
DisruptionGiven a tree and extra weighted edges, for each tree edge report the minimum weight of a non-tree edge whose endpoints lie in different components after removing it.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Multiplayer MooGiven an N x N grid of cow IDs, find the largest connected region of one ID and the largest region formed by two IDs together.Hard8DFSGraph+2No attempts yet2s512 MBJudgeable
DuathlonCount ordered triples (s, c, f) of distinct vertices such that some simple path visits s, then c, then f, in an undirected graph with n up to 1e5.Hard8GraphBFS+2No attempts yet1s1024 MBJudgeable