Pagini recente » Cod sursa (job #3204463) | Cod sursa (job #3198036) | Cod sursa (job #1833560) | Cod sursa (job #1545319) | Cod sursa (job #545114)
Cod sursa(job #545114)
#include <stdio.h>
#include <algorithm>
#define Nmax 200002
#define LL long long
using namespace std;
struct muchie{
int a,b; LL c1,c2;
inline bool operator < ( const muchie &o ) const{
return c1 == o.c1 ? ( c2>o.c2 ) : c1<o.c1;
}
} V[Nmax];
int TT[Nmax],Rg[Nmax],ind[Nmax];
int N,M;
inline int cmp(int i,int j){
return V[i] < V[j];
}
inline int Find(int x){
int r,y;
for(r=x; r!=TT[r]; r=TT[r]);
while( x!=TT[x] ){
y=TT[x];
TT[x]=r;
x=y;
}
return r;
}
inline void Merge(int x,int y){
if( Rg[x] > Rg[y] ) TT[y]=x;
else TT[x]=y;
if( Rg[x] == Rg[y] ) Rg[y]++;
}
int main(){
int i,t1,t2;
freopen("lazy.in","r",stdin);
freopen("lazy.out","w",stdout);
scanf("%d%d",&N,&M);
for(i=1;i<=M;++i){
scanf("%d%d%lld%lld",&V[i].a,&V[i].b,&V[i].c1,&V[i].c2);
TT[i]=i; Rg[i]=1;
ind[i]=i;
}
sort(ind+1,ind+M+1,cmp);
for(i=1;i<=M;++i){
t1=Find(V[ind[i]].a);
t2=Find(V[ind[i]].b);
if(t1!=t2){
Merge(t1,t2);
printf("%d\n",ind[i]);
}
}
fclose(stdin); fclose(stdout);
return 0;
}