#include #include #include using namespace std; #define MAXN 100100 #define MAXM 100100 struct aresta{ int a, b, c; aresta(){} aresta( int aa, int bb , int cc ){ a=aa; b=bb; c=cc; } void read(){ scanf("%d %d %d",&a,&b,&c); } bool operator < ( aresta a ) const { return c > a.c; } }; int n, m, q, atual; aresta v[MAXM]; int pai[MAXN]; set s[MAXN]; int resp[MAXM]; int find( int a ){ if( pai[a]==a ){ return a; } return pai[a]=find(pai[a]); } void join( int a, int b ){ int i=find(a); int j=find(b); if( i!=j ){ if( s[i].size() < s[j].size() ){ swap(i,j); } pai[j]=i; set::iterator it; for( it=s[j].begin() ; it!=s[j].end() ; it++ ){ if( s[i].count(*it)>0 ){ resp[*it]=atual; s[i].erase(*it); } else{ s[i].insert(*it); } } s[j].clear(); } } int main(){ int i, a, b; scanf("%d %d",&n,&m); for( i=0 ; i