Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for(i = 0; i < n*(n-1)/2; i++) {
- rib kruscal=q.ExtractMin();//минимальное ребро из очереди
- int t1,t2;
- t1=graph[kruscal.from].parent;
- while(t1!=graph[t1].parent)
- t1=graph[t1].parent;
- t2=graph[kruscal.to].parent;
- while(t2!=graph[t2].parent)
- t2=graph[t2].parent;
- if(t1==t2)
- continue;
- else{
- graph[t2].parent=graph[t1].parent;
- answer+=kruscal.distance;
- c++;
- }
- if(c==n-1) break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement