Def findCriticalAndPseudoCriticalEdges (n, edges) :
For I in range (len (edges) :
Edges [I]. Append (I)
Edges. Sort (key=lambda x: x [1])
Key=kruskal (n, edges, [], 0) # initial figure of the minimum spanning tree weight
Anw=[[], []]
For I in range (len (edges) :
Temp=[]
For j in range (len (edges) :
If I! J: temp. Append (edges [j])
M=kruskal (n, temp, [], 0) # in the original figure minus the edge weights of the corresponding minimum spanning tree
N=kruskal (n, temp, [edges [I] [0], edges [I] [1]], the edges [2]) # default starting from this side of the original figure can find the minimum spanning tree of a weight
If m & gt; Key:
Anw [0]. Append (edges [I] [3])
Elif n==key:
Anw [1]. Append (edges [I] [3])
Return anw
Def kruskal (n, Ed, Point, nuke) :
If len (Point)==n: return nuke
For I in range (len) (Ed) :
Tt=0
If Ed [I] [0] not in Point:
Point. Append (Ed [I] [0])
Tt=1
If Ed [I] [1] not in Point:
Point. Append (Ed [I] [1])
Tt=1
If tt==1:
Nuke +=Ed [I] [2]
If len (Point)==n: break
Print (nuke)
If len (Point)! 1
=n: return -Return nuke
,1,1 print (findCriticalAndPseudoCriticalEdges (5, [[0], [1, 2, 1], [31] 2, 31 [0], [0, 3], [3, 3], [1 minus 2]]))
Brush algorithm, the code above solution is to find a not to have the right to key and pseudo key while in this picture, but the following kruskal function parameters for (the number of nodes, the side information, a collection of points is connected, preset weights of the initial value of the minimum spanning tree), it eventually returns the input figure of minimum spanning tree corresponding weights,
But ran ran, nuke +=Ed [I] [2] this line to I called the 'int' object is not iterable this wrong, found that after the call several times kruskal function, used to record a weight inside the plastic variable nuke puzzling became a list
Confusion, solve, what is this pycharm or python source birth defects?
CodePudding user response:
Line 12 to parameter is kruskal edges [2], it is a list