Practice Remove Max Number of Edges to Keep Graph Fully Traversable
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
The undirected graph has n nodes and edges [type,u,v]. Type 1 is usable only by Alice, type 2 only by Bob, and type 3 by either. Remove as many edges as possible while keeping every node reachable from every other node separately for each person using their permitted edges. Return that maximum removal count, or -1 if it cannot be achieved.
Source: Remove Max Number of Edges to Keep Graph Fully Traversable on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]
2
# Example 2
n = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]
0
# Example 3
n = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Remove Max Number of Edges to Keep Graph Fully Traversable.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.