Programming in UVa
Pages
Home
Programming Tips
Easy List
Books
Codes
Tuesday, August 26, 2014
Minimum Spanning Tree by kruskal
Algorithm Name:
Kruskal
Algorithm Category:
Graph search algorithm
Source Code:
////////////////////////////////////////////// // Bismillahir Rahmanir Rahim // // Author : Shohan Ahmed Sijan // // Country : Bangladesh // // University : East West University // ///////////////////////////////////////// #include
#include
#include
#include
#include
#include
using namespace std; #define N 1000 int i,node,tedge,leader[N]; struct st { int x,y,cost; }edge[N]; bool cmp(st a,st b) { return a.cost
Input:
5 7 1 2 3 2 3 2 1 5 7 5 4 2 3 4 5 1 4 4 3 5 4
Output:
5 How many node: 5 How many edge: 7 X Y Cost 1<=x,y<=n 1 2 3 2 3 2 1 5 7 5 4 2 3 4 5 1 4 4 3 5 4 Edge for kruskal is: 2 3 2 5 4 2 1 2 3 1 4 4 Lowest cost is 11
No comments:
Post a Comment
Older Post
Home
Subscribe to:
Post Comments (Atom)
Followers
No comments:
Post a Comment