Skip to the code
cf.
+50 XP

#478 Servers Whose Failure Splits the Network

hard

The same dashboard also flags servers that are single points of failure. Servers are numbered 0 to n - 1, and cables[i] = [a, b] is a two-way cable.

A critical server is one whose failure (removing it and its cables) leaves some pair of the remaining servers that were connected unable to reach each other. Write criticalServers(n, cables) that returns the critical servers sorted ascending.

Example 1

Input: n = 5, cables = [[0,1],[1,2],[2,0],[1,3],[3,4]]
Output: [1,3]

Without server 1, server 3 loses its link to the triangle. Without server 3, server 4 is cut off.

Example 2

Input: n = 3, cables = [[0,1],[1,2],[2,0]]
Output: []

In a triangle, the other two servers still share a cable when any one fails.

Constraints

  • 1 <= n <= 10000
  • 0 <= cables.length <= 50000
  • 0 <= a, b < n, a !== b
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).