All problems
Percolation Threshold Check
Problem
Estimate percolation behavior by randomly removing a fraction of nodes and measuring the largest remaining component.
Call random.seed(seed), choose int(n * remove_fraction) distinct nodes to delete, and return the size of the largest connected component divided by n. Return 0.0 when nothing remains. edges is a list of [u, v] pairs.
Hint
Percolation thresholds mark where the giant component suddenly disappears.
Test cases
case 1
in: [4,[[0,1],[1,2],[2,3]],0.25,42]
expected: 0.75
case 2
in: [5,[[0,1],[1,2],[2,3],[3,4],[4,0]],0.4,7]
expected: 0.6
case 3
in: [3,[[0,1],[1,2]],0,1]
expected: 1
case 4
in: [2,[[0,1]],1,5]
expected: 0
Starter codePython
import random
def percolation_check(n, edges, remove_fraction, seed):
# Your code here
pass4 test cases · run your code against them in the editor