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 results166 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
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
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
Cable DonationGiven an adjacency matrix of cable lengths between rooms encoded as letters, find a minimum spanning tree and output the maximum total cable length that can be donated, or -1 if the rooms cannot all be connected.Medium4Minimum spanning treeGraph+2No 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
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
Underground CablesGiven up to 1000 points, connect them all with straight line segments of minimum total length, with no two segments crossing.Medium4Minimum spanning treeGraph+2No attempts yet1s128 MBJudgeable
Bad CowtractorsGiven an undirected weighted graph, find a spanning tree of maximum total edge cost, or report -1 if no spanning tree exists.Medium4Minimum spanning treeGreedy+2No attempts yet1s128 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
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
Planet ConnectionGiven a complete symmetric cost matrix, find a minimum spanning tree connecting all planets and output its total maintenance cost.Medium4Minimum spanning treeGraph+2No attempts yet1s256 MBJudgeable
Watering FieldsGiven well-digging costs per field and pairwise pipe-connection costs, compute the minimum total cost to give every field water using an MST-style approach with a virtual water source.Medium5Minimum spanning treeGraph+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
Underground CablesGiven up to 1000 points in the plane, find the minimum total length of non-crossing straight cables that connect all points.Medium5Minimum spanning treeGraph+1No attempts yet1s128 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
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
Time Is MoneyWe choose N-1 links forming a spanning tree minimizing SumTime*SumMoney, where each edge has a time and a money cost.Medium5Minimum spanning treeGeometry+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
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
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
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
BridgeConnect all axis-parallel rectangular islands with bridges of minimum total squared shortest gap distance.Medium5Minimum spanning treeGeometryNo 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
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
SightseeingFrom node 1, route each destination along roads to make the weakest road on the path as strong as possible.Medium5HeapMinimum spanning tree+1No attempts yet3.5s512 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
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
Connecting Edges 2Given a weighted edge list, pick the order of adding edges that makes the total weight added up to the moment s and t first become connected as small as possible.Medium5GraphSorting+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
Security System InstallationBuild a minimum spanning tree from the given network, then find the vertex minimizing the sum of shortest distances to all other vertices within that tree.Medium6Minimum spanning treeGraph+1No attempts yet2s128 MBJudgeable
Grand CanalGiven a graph with edge widths, use maximum-spanning-tree logic to answer K queries for the widest ship that can travel between two given cities.Medium6Union-findMinimum spanning tree+1No attempts yet1s128 MBJudgeable
Driving RangeGiven a weighted undirected graph, find the smallest range R such that using only edges of length at most R keeps the whole graph connected, or report IMPOSSIBLE.Medium6GraphUnion-find+2No attempts yet1s128 MBJudgeable
Cables ... in Spaaace!Given a planet's diameter and up to 100 city coordinates, compute the minimum cable length of a strongly connected network and compare it to the available length L.Medium6GraphMinimum spanning tree+2No attempts yet1s128 MBJudgeable
TsunamiPlace a warning center and connect cities with cables so every city reaches the center, no city is warned from a city farther from the shore, and total cable length is minimized.Medium6GraphMinimum spanning tree+2No attempts yet1s128 MBJudgeable
WarfareGiven an undirected multigraph with per-edge cost as the sum of its endpoint weights, find the minimum total cost of edges whose removal destroys every cycle.Medium6GraphMinimum spanning tree+2No attempts yet1s128 MBJudgeable
Will Indiana Jones Get There?Given axis-aligned wall segments, find the smallest board length such that a path from the first wall to the second keeps every gap no larger than that length.Medium6GraphUnion-find+2No attempts yet1s128 MBJudgeable
Truck HistoryConnect all truck codes so the total Hamming distance is minimized, then print 1/Q. This is a minimum spanning tree on a complete graph.Medium6Minimum spanning treeGraph+2No attempts yet1s128 MBJudgeable
Connect the CampusGiven N points in the plane and some already-built zero-cost edges, add edges connecting all points at minimum total Euclidean length.Medium6Minimum spanning treeUnion-find+2No attempts yet1s128 MBJudgeable
Printed CircuitGiven a grid with some existing vertical and horizontal wires, add wires to connect all nodes, minimizing cost with vertical at 1 and horizontal at 2, then report the count and cost.Medium6GraphMinimum spanning tree+1No attempts yet1s128 MBJudgeable
The Shell GameBuy interval parity hints to fix every ball position while minimizing the worst-case total price.Medium6Minimum spanning treeGraphNo attempts yet1s256 MBJudgeable
Landline Telephone NetworkFind the cheapest network joining all buildings so no route between two buildings passes through a different insecure building.Medium6Minimum spanning treeUnion-find+2No attempts yet2s256 MBJudgeable
SuperbullPick N minus 1 pairings that connect all team IDs into one group so the sum of pairwise XOR values is as large as possible.Medium6Minimum spanning treeGraph+1No attempts yet1s256 MBJudgeable
Model RailroadDecide if the existing tracks can be replaced, within the same total length budget, so that all stations become connected.Medium6Minimum spanning treeUnion-find+1No attempts yet2s512 MBJudgeable
School TourChoose a spanning tree of the graph rooted at the entrance that contains the fixed edge to building 1, find the min and max possible number of uphill edges among its edges, and print (max)^2 - (min)^2.Medium6Minimum spanning treeUnion-find+2No attempts yet1s256 MBJudgeable
Paths in MultigraphFind the minimum number of edges to delete from an undirected multigraph so the remaining graph becomes disconnected.Medium6GraphMinimum spanning tree+1No attempts yet2s512 MBJudgeable
Cutting edges 2Given a weighted undirected graph and two vertices s and t, find the minimum total weight of edges to delete so that s and t end up disconnected, choosing the deletion order.Medium6Minimum spanning treeGraph+2No attempts yet2s512 MBJudgeable
Frog PushersAfter channels are cut one by one in a fixed order, report the minimum spanning forest weight of the surviving graph before each cut, or FAIL if it is disconnected.Medium6Union-findGraph+2No attempts yet5s512 MBJudgeable
MST GameGiven an edge-weighted simple graph and a turn count K, find the MST cost each turn and delete the lightest MST edge after each turn, outputting 0 once the graph has no spanning tree.Medium6Minimum spanning treeGraph+2No attempts yet2s512 MBJudgeable
Jurassic JigsawGiven n DNA strings of length k, build a spanning tree minimizing the total Hamming distance over its edges, and print the cost plus the edges.Medium6Minimum spanning treeGraph+2No attempts yet1s512 MBJudgeable
European TripChoose N-1 roads to keep every country connected, then find the closed tour that pays each road cost twice plus visit costs, and return the least total.Medium7Minimum spanning treeGraph+2No attempts yet2s128 MBJudgeable
Architects' CountryConnect disjoint cities with new roads and pick an order to build required houses so total payments to participating architects are minimized.Medium7Minimum spanning treeGreedy+2No attempts yet2s128 MBJudgeable
Stable NetworkGiven a star network from a hub plus some existing branch edges, add minimum-cost edges among branches so the whole network stays connected after any single edge or node fails (2-connectivity via biconnected components and MST on component graph).Medium7Union-findMinimum spanning tree+1No attempts yet2s128 MBJudgeable
RoadsDecide whether the graph has a spanning tree with exactly K gravel edges, where each road is gravel or concrete.Medium7GraphMinimum spanning tree+2No attempts yet1s128 MBJudgeable
Arctic NetworkGiven P outposts and S satellite channels, find the minimum radio range D so that all outposts stay connected, where satellite-linked outposts communicate freely.Medium7Minimum spanning treeUnion-find+2No attempts yet1s128 MBJudgeable
Power Cables to Sewer PipesFor each graph, remove a maximum-length set of edges while keeping the graph connected, then count the integer partitions of the removed length in meters.Medium7GraphMinimum spanning tree+2No attempts yet1s128 MBJudgeable
Red-Blue Spanning TreeGiven a connected graph with red and blue edges, decide whether some spanning tree has exactly k blue edges.Medium7Union-findGraph+2No attempts yet3s256 MBJudgeable
Minimum Spanning TreeGiven a weighted graph and several spanning trees written as nested lists, decide for each whether it is a minimum spanning tree.Medium7Minimum spanning treeUnion-find+2No attempts yet1s128 MBJudgeable
Connecting IslandsConnect all island polygons with bridges between vertices, each bridge crossing only water, minimizing the total length of the bridges.Medium7GeometryMinimum spanning tree+2No attempts yet1s128 MBJudgeable
Animal FarmGiven M pens sharing walls, find the minimum total wall-removal cost so that all animals gather in one connected region, inside one pen or outside all pens.Medium7GraphMinimum spanning tree+2No attempts yet2s512 MBJudgeable
Domino PuzzleAdd dominoes of minimum total pip-sum so that all pieces form one row with matching ends, an Eulerian path completion on values 1 to 6.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
Buy or BuildPick a subset of up to 8 subnetworks to buy and build edges so all n cities connect, minimizing total cost.Medium7Minimum spanning treeGraph+2No attempts yet1s128 MBJudgeable
Railway NetworkGiven a connected edge-weighted graph and at most 8 terminals, find the minimum cost edge set that keeps all terminals mutually connected.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
Road RenovationChoose a cheapest set of directed roads so every city has at least one chosen road entering and one leaving it, or report impossibility.Medium7GraphMinimum spanning tree+2No attempts yet1s128 MBJudgeable
EvacuationFind the minimum number of directed edges to remove so that no path of length at most three remains from node 1 to node n.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
Highway Construction PlanChoose a spanning tree of a connected weighted graph that uses at most d edges incident to vertex 1, minimizing total cost.Medium7GraphMinimum spanning tree+1No attempts yet1s192 MBJudgeable
BytelandDecide for every proposed road whether some cheapest network connecting all towns can include it.Medium7Minimum spanning treeUnion-find+1No attempts yet1s512 MBJudgeable
Tour BeltFor each test case the program sums the sizes of connected island groups whose weakest inner synergy beats every outgoing synergy.Medium7Minimum spanning treeUnion-find+1No attempts yet1s128 MBJudgeable
Safe Emergency Contact NetworkFor each road, report the cheapest total cost of a network connecting all villages without that road, or -1 when impossible.Medium7Minimum spanning treeTree+1No attempts yet1s64 MBJudgeable
There is No AlternativeCount the bridges that appear in every minimum-cost set connecting all islands and report their total cost.Medium7Minimum spanning treeUnion-find+1No attempts yet3s256 MBJudgeable
Hiking in the HillsFind a route from camp A to lookout B across the triangulated landscape whose highest point is as low as possible.Medium7Union-findMinimum spanning tree+2No attempts yet2s256 MBJudgeable
Minimum spanning tree after deleting one edgeFor each edge, report the MST weight of the graph with that edge removed, or -1 when it disconnects.Medium7Minimum spanning treeTree+1No attempts yet3s256 MBJudgeable
Minimum Median Spanning TreeFor each connected graph with an even node count, find the spanning tree whose median edge cost is smallest and report that median.Medium7Minimum spanning treeUnion-find+1No attempts yet8s256 MBJudgeable
Bridge Construction PlanningFind the cheapest spanning tree that uses exactly k edges from company A and the rest from company B, or report that none exists.Medium7Minimum spanning treeBinary searchNo attempts yet1s256 MBJudgeable
Awkward GroupCount the subsets whose largest inner closeness is smaller than every closeness to the outside.Medium7Minimum spanning treeUnion-find+1No attempts yet5s256 MBJudgeable
AquariumFind the cheapest set of diagonal cell walls to remove so the whole R by C aquarium becomes one compartment.Medium7Minimum spanning treeUnion-find+1No attempts yet3s256 MBJudgeable
Fenced InRemove fence segments between adjacent field regions so every region connects with the smallest possible total removed length.Medium7Minimum spanning treeGreedy+1No attempts yet2s512 MBJudgeable
Fenced In (Gold)Remove fence segments of minimum total length so every region of the fenced grid connects to every other.Medium7Minimum spanning treeGreedy+1No attempts yet2s512 MBJudgeable
CitiesGiven a weighted undirected graph, pick a minimum-cost set of edges so that all k special cities (k at most 10) end up in one connected component.Medium7Minimum spanning treeDynamic programming+2No attempts yet4s256 MBJudgeable
Masonry BridgeGiven a connected undirected graph with edge weights, find the minimum over edge orderings of the earliest time island 1 and island N connect, and the maximum such time.Medium7GraphMinimum spanning tree+2No attempts yet2s128 MBJudgeable
The Sadness of DivisionSplit N members into two camps, respecting fixed members, to minimize the total weight of pairs split across camps, and output the lexicographically smallest camp A.Medium7GraphMinimum spanning tree+2No attempts yet1s512 MBJudgeable
Selecting the capitalGiven a connected multigraph where city i links to city R[i], merge adjacent cities the fewest times so that some city lies on every simple path between any two cities.Medium7GraphMinimum spanning tree+2No attempts yet2s512 MBJudgeable
Jack EdmondsChoose at most n-1 Manhattan-distance roads so the round trip from the origin visiting all points (reusing edges freely) is shortest.Medium7Minimum spanning treeGraph+1No attempts yet2s256 MBJudgeable
TrucksGiven an undirected weighted graph, answer S queries asking for the maximum bottleneck (minimum edge on the best path) between two vertices.Medium7GraphMinimum spanning tree+2No attempts yet2s512 MBJudgeable
Road ConstructionGiven a weighted bidirectional graph, find the minimum total building cost of a spanning subgraph that keeps every pairwise connection and preserves the shortest distance from the capital to every city.Medium7GraphShortest path+2No attempts yet8s512 MBJudgeable
Proving PropositionsChoose directed edges so all N propositions become mutually reachable, minimizing the difference between the hardest and easiest chosen proof difficulties.Medium7GraphTwo pointers+2No attempts yet2s512 MBJudgeable
Wasting the Class FundEach friend gives one of two opposite demands on a Ppokppoki color and a Kkokkkoki model; choose buys to maximize satisfied friends and report the rest.Medium7GraphMinimum spanning tree+2No attempts yet2s512 MBJudgeable
Delivering GoodsGiven a directed weighted graph and a set of client junctions, find the minimum number of trucks so each client is reached at its shortest-path time.Medium7GraphShortest path+2No attempts yet5s512 MBJudgeable
ConquerorConquer all cities from city 1, where the k-th city you take costs the edge cost plus (k-1)*t, and minimize the total.Medium7Minimum spanning treeGreedy+2No attempts yet2s256 MBJudgeable
How Many to Be Happy?For each edge find the fewest edges to delete so that it lies in some minimum spanning tree, then sum those counts.Medium7Minimum spanning treeGraph+2No attempts yet0.5s512 MBJudgeable
dgeu-learningGiven a connected weighted graph, answer queries for the maximum bottleneck path value between pairs of vertices.Medium7Minimum spanning treeUnion-find+2No attempts yet4s512 MBJudgeable
Red Blue Spanning Tree 2Given a connected undirected graph whose edges are red or blue, decide whether some spanning tree uses exactly k blue edges, and print one if it does.Medium7GraphMinimum spanning tree+2No attempts yet1s128 MBJudgeable
Grid NetworkGiven a grid graph whose edge costs are 1 to 4 with distinct costs around every vertex, find the minimum spanning tree cost.Medium7Minimum spanning treeGraph+2No attempts yet2s256 MBJudgeable