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 results505 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
LiesUsing union-find on party attendees, determine which parties can be exaggerated without conflicting with people who must always hear the truth.Easy3Union-findGraph+1No attempts yet2s128 MBJudgeable
Disjoint Set OperationsImplement a union-find structure that merges sets and answers whether two elements share a set across a sequence of operations.Easy3Union-findNo attempts yet2s128 MBJudgeable
Avoiding Food WasteGiven a grid marked with food waste cells, find the size of the largest 4-directionally connected component using BFS/DFS or union-find.Easy3BFSDFS+1No attempts yet2s128 MBJudgeable
Travel PlanGiven an adjacency matrix of cities, decide if consecutive cities in a given visit order all lie in the same connected component.Easy3Union-findGraph+1No attempts yet2s128 MBJudgeable
NetworkingGiven points and weighted candidate cable routes, compute the minimum total cable length needed to connect all points (minimum spanning tree).Easy3Minimum spanning treeGraph+1No attempts yet1s128 MBJudgeable
Connected or Not ConnectedGiven a graph with n sites and k edges, decide whether every site can reach every other.Easy3GraphDFS+1No attempts yet1s128 MBJudgeable
Social Networking ApplicationGiven a friendship graph, answer queries asking whether two users lie in the same connected component.Easy3Union-findGraph+2No attempts yet1s128 MBJudgeable
Rectangle ColoringCount the groups of overlapping rectangles where touching edges count as overlap and each group gets one color.Easy3Union-findGeometryNo attempts yet1s128 MBJudgeable
The SuspectsCount every student connected to student 0 through shared groups, since one suspect makes each joined group suspect.Easy3Union-findNo attempts yet1s128 MBJudgeable
Counting Communication GroupsCount the connected groups of camps whose circular communication areas touch or overlap.Easy3Union-findGeometryNo attempts yet8s256 MBJudgeable
Rings of SaturnFind every connected group of exactly seven people, sum the threat levels inside each group, and list them by total threat.Easy3Union-findSortingNo attempts yet2s256 MBJudgeable
Manhattan Power FailureCount the blocks linked by intact lines into regions and report how many regions hold no generator.Easy3Union-findGraphNo attempts yet1s256 MBJudgeable
Club Room Project (Small)Given N rooms in a row and M wall-breaking actions, count how many rooms remain after all actions merge neighboring rooms.Easy3Union-findImplementationNo attempts yet1s512 MBJudgeable
ExploraceGiven a weighted undirected graph of checkpoints, find the minimum total length of edges that keeps every checkpoint connected.Easy3Minimum spanning treeGraph+2No attempts yet3s512 MBJudgeable
TreehousesConnect all treehouse points plus the first e ground access points by cables of minimum total length, given some cables already exist; output the added length as a MST problem.Easy3Minimum spanning treeUnion-find+2No attempts yet2s512 MBJudgeable
Minimum Spanning TreeCompute the total edge weight of a minimum spanning tree for a weighted undirected graph with up to 10,000 vertices and 100,000 edges, allowing negative weights.Medium4Minimum spanning treeUnion-find+1No attempts yet1s128 MBJudgeable
Different Religions on CampusGiven pairs of students sharing a religion, compute the maximum number of distinct religions possible using union-find over multiple test cases.Medium4Union-findGraphNo attempts yet1s128 MBJudgeable
Ripple EffectValidate a filled Ripple Effect puzzle grid by checking polyomino region digit ranges and minimum-distance spacing rules for repeated numbers in rows and columns.Medium4Union-findSimulation+1No attempts yet2s128 MBJudgeable
Network ConnectionGiven N computers and M weighted possible connections, compute the minimum total cost of edges to connect all computers into one network (minimum spanning tree).Medium4Minimum spanning treeUnion-find+1No attempts yet2s256 MBJudgeable
Meeting PreparationFind connected components in a graph and for each pick the vertex minimizing the eccentricity (graph center).Medium4GraphBFS+1No attempts yet1s128 MBJudgeable
Slim SpanGiven a weighted graph, find the spanning tree that minimizes the difference between its largest and smallest edge weight, or report -1 if disconnected.Medium4Union-findSorting+1No attempts yet2s128 MBJudgeable
Jungle RoadsGiven a connected weighted graph of villages and roads, find the minimum total maintenance cost of a set of roads that keeps every village connected.Medium4Minimum spanning treeGraph+2No attempts yet1s128 MBJudgeable
Stock ChaseGiven share-purchase transactions between companies in order, count how many must be rejected because they would create a cycle.Medium4Union-findGraphNo attempts yet1s128 MBJudgeable
Money MattersGiven each person's balance and a friendship graph, decide whether all debts can be settled by moving money only within connected components.Medium4Union-findGraph+1No attempts yet1s128 MBJudgeable
Army BuddiesAfter each loss report removes living soldiers L through R, print the nearest surviving neighbors on both sides, or * when none exists.Medium4Union-findLinked list+1No attempts yet1s128 MBJudgeable
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.Medium4GraphUnion-find+2No attempts yet1s128 MBJudgeable
ChochlikDecide for each department whether wheels linked by same-direction and opposite-direction belts can all spin without contradiction.Medium4Union-findGraph+1No attempts yet1s512 MBJudgeable
More Fun in BicolGiven unit compass offsets between named places, answer each query with the direction from one place to the other or report it as unknown.Medium4Union-findGraphNo attempts yet5s128 MBJudgeable
Watering the FieldsConnect all fields with pipes costing at least C while minimizing total squared distance, or report -1 when impossible.Medium4Minimum spanning treeUnion-find+1No attempts yet1s128 MBJudgeable
Pangaea 1After each added road, compute the cheapest total length connecting all cities and XOR the m totals per test case.Medium4Minimum spanning treeUnion-find+1No attempts yet20s256 MBJudgeable
AirportEach arriving plane takes the largest free gate up to its limit gi, and the count stops at the first plane with no free gate.Medium4Union-findGreedyNo attempts yet1s256 MBJudgeable
Troop MovementFind the route between two cities whose narrowest road is as wide as possible and report that width.Medium4Minimum spanning treeUnion-find+1No attempts yet2s256 MBJudgeable
One Stroke DrawingDecide whether given line segments form a shape drawable in one stroke without retracing any segment.Medium4GraphUnion-findNo attempts yet2s256 MBJudgeable
Number Sets (Small)Count how many disjoint sets remain after merging numbers in [A, B] that share a prime factor of at least P.Medium4Union-findNumber theoryNo attempts yet5s512 MBJudgeable
Watersheds (Small)Given a height grid, follow each cell's outflow to its sink and label cells by shared sink, choosing basin letters to make the row-wise string smallest.Medium4GraphDFS+2No attempts yet5s512 MBJudgeable
The Enemy of My EnemyDecide whether the N people can be split into two camps so that every given hostile pair lands on opposite sides, which is exactly bipartiteness.Medium4GraphBFS+2No attempts yet2s512 MBJudgeable
TreeGiven up to 10 graphs, decide for each whether it is a tree, allowing self-loops and duplicate edges.Medium4GraphUnion-find+1No attempts yet2s512 MBJudgeable
Balls and NeedlesGiven K segments in 3D defined by endpoint triples, decide whether they form a closed cycle in space and whether their projections onto the xy-plane form a closed cycle.Medium4GraphUnion-find+2No attempts yet2s512 MBJudgeable
Rebel Against The Empire (Small)Given stationary points in 3D, find the smallest jump radius that lets you reach asteroid 1 from asteroid 0, ignoring the time limit.Medium4GraphUnion-find+2No attempts yet5s512 MBJudgeable
Club Room Project (Large)For each action, remove all walls between rooms x and y; print how many connected room blocks remain.Medium4Union-findArrayNo attempts yet1s512 MBJudgeable
League of Overwatch at Moloco (Hard)Given n employees and m conflict pairs, decide whether the employees can be split into two non-empty groups so that no pair shares a group.Medium4GraphDFS+1No attempts yet2s512 MBJudgeable
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.Medium4GraphDFS+2No attempts yet1s512 MBJudgeable
Toy AlliancesGiven N toys and M dislike pairs, decide whether the toys can be split into two alliances so no dislike pair shares a side, which is checking bipartiteness of the graph.Medium4GraphBFS+2No attempts yet1.5s256 MBJudgeable
Connecting a Road GraphGiven an adjacency matrix, find the minimum number of edge-swap operations needed to make the graph fully connected, or report -1 if impossible.Medium5GraphUnion-find+1No attempts yet2s128 MBJudgeable
City Division PlanSplit a connected weighted graph into two connected subvillages by removing edges so that the total remaining maintenance cost is minimized.Medium5Minimum spanning treeUnion-find+2No attempts yet2s256 MBJudgeable
Communicating with the Space GodsGiven points with some already connected, find the minimum total length of new passages needed to connect all points into one network.Medium5Minimum spanning treeUnion-find+2No attempts yet2s128 MBJudgeable
Designing a High-Speed Rail NetworkGiven a cost matrix where negative values mark already-built rail lines, compute the minimum spanning tree cost forcing existing lines and list the new lines to build.Medium5Minimum spanning treeUnion-find+2No attempts yet2s128 MBJudgeable
Weight LimitGiven a weighted undirected graph, find the maximum possible minimum edge weight (bottleneck) along any path between two given nodes.Medium5Union-findBinary search+1No attempts yet1s128 MBJudgeable
Stable GroupGiven a like/dislike matrix, decide if people can be partitioned into groups (size at least 2) where members like each other within groups and dislike each other across groups, and output that partition.Medium5Union-findGraph+1No attempts yet1s128 MBJudgeable
Crane DeliveryGiven cranes with fixed positions and reach radii starting from a fixed entrance point, decide for each of K target points whether it lies in the union-reachability graph of overlapping crane discs starting from the entrance.Medium5GraphUnion-find+1No attempts yet1s128 MBJudgeable
Play on WordsDetermine whether all given words can be chained into one sequence where each word's first letter matches the previous word's last letter, using Eulerian path conditions on a letter graph.Medium5GraphUnion-find+1No attempts yet1s256 MBJudgeable
Network ConnectionSimulate weighted union operations that always merge into the second cluster's center, and answer path-length queries to the current cluster center.Medium5Union-findImplementation+1No attempts yet1s128 MBJudgeable
Bridges and TunnelsAfter each new edge between two named buildings, print the size of the connected component that the edge joins.Medium5Union-findHash map+2No attempts yet3s128 MBJudgeable
Building the ConstellationGiven n points in the plane, connect all of them with straight segments of Euclidean length so the total cost is minimized.Medium5Minimum spanning treeGraph+2No attempts yet1s128 MBJudgeable
Crash and Go(relians)After each Gorelian lands in order, groups merge when one radio reaches another, meeting at the unweighted average of group positions and combining ranges by root sum of squares; report the final group count.Medium5SimulationUnion-find+2No attempts yet1s128 MBJudgeable
Tangled in CablesCompute the minimum spanning tree of a town map and compare its total length against the available spool of cable.Medium5Minimum spanning treeGraph+2No attempts yet1s128 MBJudgeable
TreesGiven an undirected graph, count its connected components that contain no cycle and report the count per test case.Medium5GraphUnion-find+2No attempts yet1s256 MBJudgeable
ConstellationsGiven up to 500 star coordinates, connect each star to its nearest neighbor(s) and count the connected components of the resulting graph.Medium5GraphUnion-find+2No attempts yet1s128 MBJudgeable
Tea TimeStarting from a graph of known meetings, two cows meet whenever they share a mutual friend, and after all rounds settle, answer queries about whether each pair has met.Medium5GraphUnion-find+2No attempts yet1s128 MBJudgeable
Power ShortageGiven a connected weighted undirected graph, keep a subset of roads so every pair of houses stays connected while maximizing the total length of removed roads.Medium5Minimum spanning treeGraph+2No attempts yet1s256 MBJudgeable
Railway ConnectionGiven existing rail links and city flows, find the minimum cost to connect all cities, where an edge costs the product of its endpoint flows.Medium5Minimum spanning treeUnion-find+2No attempts yet1s1024 MBJudgeable
HighwaysConnect all towns with the cheapest new highways, where some links already exist, and report the summed squared lengths of the added edges.Medium5Minimum spanning treeUnion-findNo attempts yet1s128 MBJudgeable
A Bug's LifeGiven pairs of interacting bugs, decide whether a two-gender assignment exists so that no pair shares a gender.Medium5Union-findGraphNo attempts yet3s256 MBJudgeable
Heavy TransportationFind the maximum weight that can travel from crossing 1 to crossing n, defined as the path whose smallest street limit is as large as possible.Medium5GraphMinimum spanning tree+2No attempts yet1s128 MBJudgeable
Piggy BanksEach key i sits in some bank; opening a bank frees its keys. Find the minimum number of banks to smash to reach all N banks.Medium5GraphDFS+2No attempts yet3s128 MBJudgeable
TilesGiven n, k, l, find the number of equivalence classes of positions 1..n under the equivalence generated by steps of ±k and ±l.Medium5Number theoryUnion-find+1No attempts yet1s128 MBJudgeable
HighwaysFind a spanning tree of a connected weighted graph that minimizes the maximum edge weight, and report that weight.Medium5Minimum spanning treeGraph+2No attempts yet1s128 MBJudgeable
Word Translation LookupGiven pairs of directly translated words, list every target-language word linked to each query word through translation chains.Medium5Union-findHash map+1No attempts yet12s128 MBJudgeable
Widest PathFind the path between two given nodes whose smallest edge weight is as large as possible.Medium5Minimum spanning treeUnion-find+1No attempts yet1s128 MBJudgeable
CommunicationConnect all rooms in a 3D grid with the cheapest new links given some existing links and fixed horizontal and vertical costs.Medium5Minimum spanning treeUnion-find+1No attempts yet1s128 MBJudgeable
RoadDecide whether the road between p and q can belong to a cheapest network that connects all cities.Medium5Minimum spanning treeUnion-find+1No attempts yet2s64 MBJudgeable
SumoFind the earliest scheduled fight that forces two wrestlers on the same team to meet under the best two-team split.Medium5Union-findGraphNo attempts yet1s128 MBJudgeable
Global WarmingGiven column heights, find the greatest number of maximal above-water runs over all real sea levels.Medium5Union-findSorting+1No attempts yet2s512 MBJudgeable
Cross Country SkiingFind the smallest elevation gap D that keeps every waypoint mutually reachable through adjacent cells.Medium5Minimum spanning treeUnion-find+1No attempts yet1s512 MBJudgeable
Rat TunnelPick the cheapest lanes for cameras so every closed running route holds one, and report the total cost and the longest chosen lane.Medium5Minimum spanning treeUnion-find+1No attempts yet1s256 MBJudgeable
Not enough electricityConnect every city to exactly one of the given power plants with minimum total cable cost.Medium5Minimum spanning treeUnion-findNo attempts yet1s256 MBJudgeable
Travel between two islandsAfter each bridge joins two neighboring islands, report how many island pairs are mutually reachable and the total bridge crossings summed over those pairs.Medium5Union-findMathNo attempts yet1s16 MBJudgeable
Flipping CardsDecide whether each card can show one of its two pictures so that all n face-up pictures differ.Medium5GraphUnion-findNo attempts yet3s256 MBJudgeable
Closing the FarmBarns close one by one in a given order, and the task asks after each step whether all open barns remain connected.Medium5Union-findGraphNo attempts yet2s512 MBJudgeable
Havannah (Small)The program places the given stones in order on a hexagonal board and reports the first move that completes a ring, bridge, or fork.Medium5Union-findBFSNo attempts yet5s512 MBJudgeable
Watersheds (Large)Each cell drains to its lowest neighbor, sinks define basins, and each basin gets the letter that makes the row-major label string smallest.Medium5GraphDFS+2No attempts yet5s512 MBJudgeable
Minimum number of islandsGiven a grid of land, water, and cloud cells, find the minimum possible number of 4-connected land islands if every cloud can be either land or water.Medium5GraphDFS+2No attempts yet2s512 MBJudgeable
MoocastGiven N cow coordinates, find the smallest integer X such that the graph connecting pairs whose squared distance is at most X is connected.Medium5GraphUnion-find+2No attempts yet2s512 MBJudgeable
Why Did the Cow Cross the Road 6Given an N x N grid of pastures, some adjacent pairs blocked by roads, and K cows on distinct cells, count the pairs of cows that cannot reach each other without crossing a road.Medium5GraphBFS+2No attempts yet2s512 MBJudgeable
Love That Only Fails for MeFind the minimum spanning tree of a graph restricted to edges joining a men-majority school and a women-majority school, or report -1.Medium5GraphMinimum spanning tree+2No attempts yet2s256 MBJudgeable
Xayahh-Rakann at Moloco (Hard)Given n jars with m inseparable pairs, decide whether exactly k jars can be placed in one building so that no inseparable pair is split across the two buildings.Medium5GraphUnion-find+2No attempts yet2s512 MBJudgeable
Warring StatesProcess alliance and war records between groups, merging by sum for alliances and subtracting troops for wars, then report surviving groups sorted by troop count.Medium5Union-findImplementation+2No attempts yet1s128 MBJudgeable
Population MovementRepeat until stable: open borders whose population difference is L to R, compute each connected union's floored mean population, and count the days with any change.Medium5SimulationBFS+2No attempts yet2s512 MBJudgeable
Friendship FeeFind the cheapest way to become friends with everyone by paying each student a friend fee and using the friend-of-a-friend rule; output the minimum cost or "Oh no" when it exceeds k.Medium5Union-findGraph+1No attempts yet2s512 MBJudgeable
Structure of Balanced NetworksGiven a complete signed graph where every triad is balanced, answer queries about the sign of the edge between two nodes.Medium5GraphMath+2No attempts yet5s16 MBJudgeable
Japan SinksRaise the sea level through the section heights and track how maximal runs of above-level sections merge; report the largest island count seen.Medium5SortingUnion-find+2No attempts yet2s512 MBJudgeable
Segments and QueriesProcess up to 100 queries that add intervals of strictly increasing length and ask whether two added intervals are connected by the overlap-based move relation.Medium5GraphUnion-find+2No attempts yet1s512 MBJudgeable
Fence PlanningConnect cows into groups given moo pairs, then find the axis-aligned rectangle of smallest perimeter that fully contains one group.Medium5Union-findGraph+2No attempts yet2s512 MBJudgeable
ArchipelagoGenerate a pseudorandom sequence of edges, add each new bridge between distinct islands, and find the earliest day the whole archipelago becomes connected or report 0.Medium5Union-findSimulation+2No attempts yet1s256 MBJudgeable
Experimental ChargesParticles carry unknown plus or minus charges; process attract/repel observations online and answer whether a queried pair must attract, must repel, or is unconstrained.Medium5Union-findGraph+2No attempts yet2s512 MBJudgeable
Cutting a Cake with a HoleGiven a square cake with a smaller square hole in its center, count how many pieces result from horizontal and vertical full-line cuts that only affect actual cake material.Medium6GeometryUnion-find+2No attempts yet1s128 MBJudgeable
Colored SticksGiven colored-end sticks, decide if they can all be joined into one line where touching ends share the same color, which reduces to checking an Eulerian path exists.Medium6Union-findGraph+2No attempts yet2s128 MBJudgeable
Choosing Chicken-Fight TeamsGiven friend/enemy relations among students where friends of friends are friends and enemies of enemies are friends, find the maximum number of valid teams.Medium6Union-findGraphNo attempts yet2s256 MBJudgeable
Collecting JewelsFind the maximum jewels collectible from a graph and returned to island 1 without exceeding any bridge's jewel-carrying capacity on any crossing.Medium6Binary searchGraph+1No attempts yet2s128 MBJudgeable
Line DrawingGiven up to 10,000 line segments, count connected groups formed by segments that touch, overlap, or intersect, using geometric intersection tests combined with union-find.Medium6Union-findGeometryNo attempts yet2s128 MBJudgeable