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
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.Medium7TreeSegment tree+1No attempts yet2s512 MBJudgeable
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.Medium7TreeDFS+1No attempts yet1s512 MBJudgeable
Countries at WarGiven directed weighted edges between cities, treat mutually reachable cities as zero-cost (same country), then answer shortest path queries.Medium7Shortest pathGraph+2No attempts yet2s512 MBJudgeable
MegaDamasGiven a checkers-like board with your and opponent pieces, find the maximum number of opponent pieces one capture move can take.Medium7DFSBacktracking+2No attempts yet2s512 MBJudgeable
Critical RouteGiven a directed multigraph where every city reaches the capital, list every road segment whose removal disconnects some city from the capital.Medium7GraphDFS+1No attempts yet2s512 MBJudgeable
Tecle & SomeList every way to split S into terms of at most D digits whose concatenated digits form a path on a phone keypad using each digit at most once.Medium7DFSBacktracking+1No attempts yet2s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet8s512 MBJudgeable
Trees and PrimesGiven a tree on N vertices, find the probability that a uniformly random pair of distinct vertices has a prime distance.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
Performance ReviewFor each employee, sum t_j over all descendants j whose rank r_j is lower than the employee's rank.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
Maximum IslandsGiven an n by m grid of land, water, and cloud cells where clouds may be either, maximize the number of 4-connected land components.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
Cars on IceCars point in fixed directions and slide out along that direction; find the lexicographically smallest order that pushes every car out without collisions.Medium7Topological sortGraph+1No attempts yet5s512 MBJudgeable
Through a Maze DarklyA planar maze lists each room's neighbors in clockwise order; for each starting room, find the longest wall-following (right-hand rule) closed walk before returning to the start.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
Sorting with allowed swapsGiven a permutation and allowed swaps, decide if the given pairs can sort it and output the swaps produced by the described leaf-removal rule on the spanning forest.Medium7GraphDFS+2No attempts yet0.5s128 MBJudgeable
Tree and PrimesIn a tree, count pairs of nodes whose path length is prime, and output the probability as a reduced fraction.Medium7TreeDFS+1No attempts yet3s512 MBJudgeable
Explosion at CafebazaarA directed multigraph alternates send and receive rounds from an initial 1-bit packet; count the starting switches whose bit makes some buffer grow without bound.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
BFFs (Large)Each kid points to one BFF; find the largest circular seating where everyone sits next to their BFF.Medium7GraphDFS+2No attempts yet5s512 MBJudgeable
Promotion CountingFor each node of a rooted tree, count descendants whose value is larger than the node's own value.Medium7TreeDFS+1No attempts yet2s512 MBJudgeable
IliGiven a DAG of two-input OR gates where some gate outputs are measured, determine which remaining gate outputs are forced to a single value across all valid assignments of the wires.Medium7GraphDFS+2No attempts yet4s1024 MBJudgeable
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.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
Hiking GwanaksanOn a graph with distinct vertex heights, each hiker at a vertex must move along an edge to a strictly higher neighbor, repeating until stuck; for every start vertex find the longest such strictly increasing path length.Medium7GraphDynamic programming+2No attempts yet1s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet1s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet2s256 MBJudgeable
Treetop WalkwayGiven a weakly connected directed graph, find the minimum number of edges to add so every vertex reaches every other.Medium7GraphGreedy+1No attempts yet5s512 MBJudgeable
Intelligence InfectionFind the minimum number of spies to message so that every non-enemy spy receives the message and no enemy spy does, given a directed contact graph and a set of enemy spies.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
Journal EditingGiven theorems that depend on other theorems and multiple possible proofs with costs, find the minimum total cost to prove Theorem 0.Medium7Dynamic programmingGraph+2No attempts yet2s512 MBJudgeable
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.Medium7TreeDynamic programming+1No attempts yet1s1024 MBJudgeable
Is-A? Has-A? Who Knows-A?Given is-a and has-a facts between at most 500 classes, apply the four transitivity rules and answer whether each queried relation holds.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
UnsatisfyingGiven 2-SAT clauses, find the minimum number of clauses of the form (p_a OR p_b) to add so the whole formula becomes unsatisfiable, or -1.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
Grand TestFor each undirected graph, decide whether some pair of vertices admits three routes whose internal vertices and edges are all disjoint.Medium7GraphDFS+2No attempts yet3s512 MBJudgeable
Deck of CardsTwo players alternate playing a card matching the table card in color or value; the first unable to move loses, so find the winner under optimal play.Medium7Game theoryGraph+2No attempts yet5s512 MBJudgeable
Cactus graph edge removalDelete uniformly random edges one at a time from a cactus graph until it disconnects, and output the expected number of deletions to six decimals.Medium7ProbabilityGraph+2No attempts yet1s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet6s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
HikingOn a bipartite graph of peaks and valleys, two players alternate choosing an unvisited neighbor and the player who cannot move loses; report the winner for every starting peak.Medium7Game theoryGraph+2No attempts yet1s256 MBJudgeable
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.Medium7GraphTree+2No attempts yet5s512 MBJudgeable
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.Medium7TreeGraph+2No attempts yet2s64 MBJudgeable
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.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
Please Take My GiftEach cell of a grid holds a direction; every walk follows those arrows forever. Find the fewest cells to mark so every walk visits a marked cell.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
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.Medium7TreeDynamic programming+2No attempts yet2s64 MBJudgeable
MooTube (Gold)On a weighted tree, USADO between two videos is the minimum edge weight on their path. For each query (K, v), count vertices whose USADO with v is at least K.Medium7GraphUnion-find+2No attempts yet2s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Calculate! 2On a rooted tree, handle subtree XOR queries and subtree XOR updates, printing the XOR of a vertex and its descendants.Medium7TreeSegment tree+2No attempts yet1s512 MBJudgeable
Please Take My Gift 2Given a 1 by N arrow map where every walk stays inside, place the fewest gifts so that a walk from any starting cell hits a gift.Medium7GraphGreedy+2No attempts yet2s256 MBJudgeable
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.Medium7TreePrefix sum+2No attempts yet2s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet1s512 MBJudgeable
A Very Nasty Graph ProblemBuild the lexicographically smallest de Bruijn sequence of order N over two symbols, a shortest binary string containing every N-bit number.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
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.Medium7TreeLinked list+2No attempts yet1s512 MBJudgeable
Computer networkGiven a directed graph, find the minimum number of source computers that reach all nodes, and the minimum edges to add to make it strongly connected.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
KMPEach of N scientists has letters from the first characters of their name words. For each query, decide whether its letters can be matched one each to distinct scientists, with order ignored.Medium7Bit manipulationDFS+2No attempts yet2s512 MBJudgeable
Peg Game for TwoGiven a weighted triangular peg board with one empty hole, compute the optimal difference of Jacquez's score minus Alia's when both alternately jump and play to maximize their margin.Medium7DFSGame theory+2No attempts yet2s512 MBJudgeable
WandGiven M duels with fixed winners, in any order, decide which wizards can hold the wand (initially with wizard 1) after all duels.Medium7GraphDFS+2No attempts yet1s512 MBJudgeable
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.Medium7TreeProbability+2No attempts yet1s512 MBJudgeable
BoomerangsCount pairs of adjacent edges in a connected graph whose removal disconnects the graph.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
Five Color TheoremGiven a planar graph with coordinates and edges, assign each vertex one of five colors so no edge joins two vertices of the same color.Medium7GraphGreedy+2No attempts yet1s512 MBJudgeable
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.Medium7StringTrie+2No attempts yet10s512 MBJudgeable
Newcomer and VeteranGiven a directed reporting graph on N participants where newcomers speak truth and veterans lie, find the maximum possible number of veterans.Medium7GraphDFS+2No attempts yet2s256 MBJudgeable
HashgraphBuild a hashgraph from M directed communications, then decide whether one given event can reach another through the precedence (see) relation.Medium7GraphDFS+2No attempts yet1s256 MBJudgeable
Ant in a Hexagonal WebOn an infinite hexagonal web, count the ant walks that make exactly N turns before first revisiting a vertex, where the first step is fixed north.Medium7DFSBacktracking+2No attempts yet1s1024 MBJudgeable
TrapCount the self-avoiding walks of n unit grid steps that start at (0,0) going right and are trapped: no further step can be added without self-intersection.Medium7BacktrackingDFS+2No attempts yet2s512 MBJudgeable
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.Medium7TreeGreedy+2No attempts yet2s512 MBJudgeable
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.Medium7TreeGreedy+2No attempts yet1s512 MBJudgeable
Beer Flood SystemGiven a DAG with a unique source and unique sink, find the maximum number of edges that can be deleted while keeping every remaining edge on a valid source-to-pump-to-sink flow path.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
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.Medium7TreeDynamic programming+2No attempts yet1s512 MBJudgeable
Bus RoutesCover every edge of a tree with the fewest simple paths, where each path visits distinct vertices in order along tree edges.Medium7TreeDFS+2No attempts yet1s512 MBJudgeable
Folding a CubeGiven a connected arrangement of six unit squares with no 2x2 block, decide whether it can be folded into a cube.Medium7DFSGeometry+2No attempts yet1s512 MBJudgeable
Hidden WordsGiven a grid of up to 10x10 letters and up to 100,000 query words of length at most 10, count how many words can be traced through adjacent, non-repeating cells.Medium7BacktrackingDFS+2No attempts yet2s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet1s512 MBJudgeable
Maze ConnectGiven an ASCII maze of slashes and dots on a 45-degree grid, find the fewest walls to remove so every cell connects to the outside.Medium7GraphUnion-find+2No attempts yet5s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet4s512 MBJudgeable
EquidistantGiven a tree and a set of marked vertices, find any vertex equidistant from all marked vertices, or report that none exists.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
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.Medium7TreeHash map+2No attempts yet1s1024 MBJudgeable
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.Medium7TreeDFS+2No attempts yet3s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
Wormhole SortPermutation of cows at locations with weighted wormholes; maximize the minimum wormhole width used to place every cow at its own location.Medium7Union-findGraph+2No attempts yet2s512 MBJudgeable
Plan BFind every city that cannot be surrounded by forces, where a city is surrounded only when every neighbor holds a base or can be reached without passing through the protest city.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
PutovanjeOn a tree, visit towns 1 through N in order; each edge costs C1 per traversal or C2 once, so minimize total ticket cost.Medium7TreeGreedy+2No attempts yet1s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
Beautiful NowGiven an integer n and a swap budget k, find the smallest and largest numbers reachable by swapping digit positions, where no intermediate or final number may have a leading zero.Medium7GreedyBrute force+2No attempts yet2s512 MBJudgeable
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.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
UberficationIn an undirected unit graph, sum the shortest path distances over all unordered pairs of nodes that are connected by exactly one simple path.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
Even SeparationSplit the vertices of an undirected graph into two parts so that every vertex has even degree in the subgraph induced on its own part.Medium7GraphDFS+2No attempts yet1s256 MBJudgeable
FantasiaFor each vertex i, compute the weight of the graph with i removed, where a connected graph weighs the product of its vertex weights and a disconnected one weighs the sum of its components.Medium7GraphDFS+2No attempts yet5s64 MBJudgeable
Police StationsGiven costs and one-way roads among N villages, pick police-station villages so every village is reachable, minimizing the average station cost.Hard8GraphDFS+2No attempts yet2s128 MBJudgeable
Dance, DanceFind the maximum number of rounds of perfect man-woman pairings, with no repeated pair and each person dancing with a disliked partner at most K times.Hard8GraphBinary search+2No attempts yet2s128 MBJudgeable
Strategy Game TournamentGiven fixed win results between some pairs of N tournament players, determine every player who could still end up as champion.Hard8GraphUnion-find+2No attempts yet1s256 MBJudgeable
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.Hard8GraphDFS+2No attempts yet2s512 MBJudgeable
AlleywaysFind the maximum-value path from node 1 to node n in a directed weighted graph, or report -1 if the value can grow without bound due to a positive cycle on a valid path.Hard8Shortest pathGraph+2No attempts yet2s128 MBJudgeable
Road Direction PlanningDecide if directions for N horizontal and M vertical one-way roads can be chosen so every bus route still has a shortest path using at most one horizontal and one vertical road.Hard8GraphDFS+2No attempts yet2s128 MBJudgeable
N-RookGiven a grid with walls blocking line of sight and pit cells that block placement but not sight, find the maximum number of mutually non-attacking rooks.Hard8GraphDFS+2No attempts yet2s128 MBJudgeable
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.Hard8TreeDynamic programming+2No attempts yet2s128 MBJudgeable
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.Hard8Dynamic programmingTree+2No attempts yet2s128 MBJudgeable
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.Hard8TreeDFS+2No attempts yet2s128 MBJudgeable
Planning a TripGiven a directed graph, find the maximum number of distinct cities visitable on a walk from S to T, allowing revisits of cities and edges.Hard8GraphDFS+1No attempts yet2s128 MBJudgeable
Graph HashGiven a weighted graph with up to 30 vertices, compute the LCM over all simple paths from vertex 1 to 2 of the GCD of edge weights on each path, with results up to 1000 digits.Hard8GraphDFS+2No attempts yet2s128 MBJudgeable
Drive TourFind two vertex-disjoint (except endpoints) monotonic increasing and decreasing paths between city 1 and city N that together visit the maximum number of distinct cities, and output the combined route.Hard8Dynamic programmingGraph+1No attempts yet2s128 MBJudgeable
SticksGiven N triples of sticks, decide if removing at most one stick per triple can make all remaining sticks pairwise non-crossing, and output a valid removal set.Hard8GraphDFS+1No attempts yet1s128 MBJudgeable
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.Hard8TreeGreedy+2No attempts yet1s128 MBJudgeable
Histology Outline TracerTrace clockwise boundary contours of stained connected regions in a bitmap, ignoring small regions, using an 8-direction outline code.Hard8DFSMatrix+1No attempts yet1s128 MBJudgeable
Roman Numeral WalkFind the longest path from the grid center through empty-separated cells that spells consecutive Roman numerals starting at 1, and print the last number reached.Hard8DFSBacktracking+2No attempts yet1s128 MBJudgeable