diff --git a/Kruskal (MST): Really Special Subtree.cpp b/Kruskal (MST): Really Special Subtree.cpp new file mode 100644 index 0000000..e6291b5 --- /dev/null +++ b/Kruskal (MST): Really Special Subtree.cpp @@ -0,0 +1,68 @@ +#include +using namespace std; +struct Edge { + int u; + int v; + int weight; +} ; +bool __cmp(Edge A,Edge B){ + if(A.weight!=B.weight) + return A.weight> N >> M; + + int adj[N+1][N+1]; + for(int i=0;i<=N;i++) + for(int j=0;j<=N;j++) + adj[i][j]=INT_MAX; + for(int i=1;i<=M;i++){ + int u,v,w; cin >> u >> v >> w; + adj[u][v]=adj[v][u]=min(w,min(adj[u][v],adj[v][u])); + } + vector edges; + for(int i=1;i<=N;i++) + for(int j=1;j<=N;j++) + if(adj[i][j]!=INT_MAX) + edges.push_back({i,j,adj[i][j]}); + sort(edges.begin(),edges.end(),__cmp); + /* + for(int i=0;i > dsu(N+1); + for(int i=0;i<=N;i++) + dsu[i].first=i,//parent + dsu[i].second=1;//size + //Krushkal + long long ans = 0; + for(int i=0;i