Cod sursa(job #544053)

Utilizator swift90Ionut Bogdanescu swift90 Data 28 februarie 2011 22:43:57
Problema Lazy Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include<stdio.h>
#include<algorithm>
using namespace std;
struct muchie{
	int a,b,ind;
	long long c1,c2;
}mu[200100];
struct cmp{
	bool operator()(const muchie &x,const muchie &y){
		if(x.c1>y.c1)
			return false;
		if(x.c1<y.c1)
			return true;
		if(x.c2<y.c2)
			return true;
		return false;
	}
};
int N,M,tata[200100];
char sol[200100];
int par(int x){
	if(!tata[x])
		return x;
	return tata[x]=par(tata[x]);
}
void solve(){
	int i,x,y;
	for(i=1;i<=M;++i){
		x=par(mu[i].a);
		y=par(mu[i].b);
		if(x==y)
			continue;
		tata[x]=y;
		sol[mu[i].ind]=1;
	}
}
int main(){
	freopen("lazy.in","r",stdin);
	freopen("lazy.out","w",stdout);
	int i;
	scanf("%d%d",&N,&M);
	for(i=1;i<=M;++i){
		scanf("%d%d%lld%lld",&mu[i].a,&mu[i].b,&mu[i].c1,&mu[i].c2);
		mu[i].ind=i;
	}
	
	sort(mu+1,mu+M+1,cmp());
	solve();
	
	for(i=1;i<=M;++i){
		if(sol[i])
			printf("%d\n",i);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}