Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me find the problem and fix it def find ( u ) : global parent if ( u = = parent [ u
Please help me find the problem and fix it
def findu:
global parent
ifu parentu:
return u
parentu findparentu
return parentu
# Read in the number of vertices n and edges m
n intinput
m intinput
edges
nedges for i in rangen for j in rangen
for i in rangem:
u v w inputsplit
u intu
v intv
w floatw
edges.appenduvw
nedgesuvw
nedgesuvw
sortedeg sortededges keylambda x: x
parenti for i in rangen
count intinput
costs
for i in rangecount:
uv inputsplit
u intu
v intv
parentu findu
parentv findv
parentparentuparentv
costs nedgesuv
q
for u v w in sortedeg:
parentu findu
parentv findv
if parentu parentv:
parentparentu parentv
q w
result q costs
printroundresult
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started