Skip to content
We areTOP 1%

Remove Max Number of Edges to Keep Graph Fully Traversable

HardLeetCodeUnion-Find (DSU)
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Keep one DSU for Alice and one for Bob. Add shared type-3 edges to both first, then each person's own edges; count edges that join nothing new, and return -1 if either DSU ends up disconnected.

More in Union-Find (DSU)

Union-Find (DSU) questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Redundant ConnectionLeetCodeMedium Solve Redundant Connection on LeetCode (opens in a new tab)
2Satisfiability of Equality EquationsLeetCodeMedium Solve Satisfiability of Equality Equations on LeetCode (opens in a new tab)
3Number of Operations to Make Network ConnectedLeetCodeMedium Solve Number of Operations to Make Network Connected on LeetCode (opens in a new tab)
4News DistributionCodeforcesMedium 1400Solve News Distribution on Codeforces (opens in a new tab)
5Accounts MergeLeetCodeMedium Solve Accounts Merge on LeetCode (opens in a new tab)
6Most Stones Removed with Same Row or ColumnLeetCodeMedium Solve Most Stones Removed with Same Row or Column on LeetCode (opens in a new tab)
7Bear and Friendship ConditionCodeforcesMedium 1500Solve Bear and Friendship Condition on Codeforces (opens in a new tab)
8SocksCodeforcesMedium 1600Solve Socks on Codeforces (opens in a new tab)
9Destroying ArrayCodeforcesMedium 1600Solve Destroying Array on Codeforces (opens in a new tab)
10Path QueriesCodeforcesHard 1800Solve Path Queries on Codeforces (opens in a new tab)
11Making A Large IslandLeetCodeHard Solve Making A Large Island on LeetCode (opens in a new tab)
12Remove Max Number of Edges to Keep Graph Fully TraversableLeetCodeHard Solve Remove Max Number of Edges to Keep Graph Fully Traversable on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account