/******************************************************* * Copyright (C) 2015 Haotian Wu * * This file is the solution to the question: * https://www.hackerrank.com/challenges/kruskalmstrsub * * Redistribution and use in source and binary forms are permitted. *******************************************************/ #include #include #include #include #include #include #include #include #include #include using namespace std; // Kruskal Algorithm. Find-Union Set used here. // The starting node makes no sense. Ignore it. struct edge { int a; //From int b; //To int w; //Weight bool inline friend operator < (edge x, edge y) // Compare function. Used in sort. { if (x.w < y.w) return true; return false; } } e[4500000]; int fa[3001]; int getfa(int x) { if (fa[x] == x) return x; return fa[x] = getfa(fa[x]); } int main() { int n,m,top=0; scanf("%d %d",&n,&m); for (int i=0;i