Remove Max Number of Edges to Keep Graph Fully Traversable
An undirected graph on n nodes (labeled 1..n) has three edge types: type 1 usable only by Alice, type 2 usable only by Bob, and type 3 usable by both. edges[i] = [type, u, v]. Remove as many edges as possible while the graph remains fully traversable -- meaning Alice alone can reach every node from every node, and Bob alone can too. Return the maximum number of removable edges, or -1 if the graph cannot be made fully traversable by both.
Open official problem prompt ↗Keep the smallest set of edges that still lets both Alice and Bob independently reach every node, and report how many edges that lets us throw away.
Two delivery companies share some roads and each owns private roads. To keep both able to reach every town, first pave the shared roads (they count double), then patch each company's remaining gaps with its private roads. Any road not needed to connect a new town can be torn up.
- Input
- n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]
- Output
- 2
- Why
- Keeping both type-3 edges plus Alice's [2,4] and Bob's [3,4] connects everything for both; the remaining 2 edges ([1,1,3] and [1,1,2]) are redundant and removable.
1 <= n <= 10^51 <= edges.length <= min(10^5, 3 * n * (n-1) / 2)edges[i].length == 31 <= edges[i][0] <= 31 <= u_i < v_i <= nAll tuples (type_i, u_i, v_i) are distinct