Pagini recente » Cod sursa (job #2321447) | Cod sursa (job #2942936) | Cod sursa (job #2795561) | Cod sursa (job #272735) | Cod sursa (job #783365)
Cod sursa(job #783365)
#include<cstdio>
#include<algorithm>
using namespace std;
int N,M,i,j,nr,gx,gy;
int x[200002],y[200002],ind[200002],group[200002];
long long c1[200002],c2[200002];
struct comp
{bool operator()(const int &a, const int &b)const
{if(c1[a]==c1[b])
return(c2[a]>c2[b]);
else
return(c1[a]<c1[b]);}
};
inline int group_name(int s)
{if(group[s]==s)
return s;
group[s]=group_name(group[s]);
return group[s];
}
int unite_groups(int a, int b)
{group[group_name(b)]=group_name(a);}
int main()
{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",&x[i],&y[i],&c1[i],&c2[i]);
ind[i]=i;}
for(i=1; i<=N; i++)
group[i]=i;
sort(ind+1,ind+M+1,comp());
for(i=1; i<=M; i++)
if(nr<N-1)
{gx=x[ind[i]]; gy=y[ind[i]];
if(group_name(gx)!=group_name(gy))
{unite_groups(gx,gy);
nr++;
printf("%d\n",ind[i]);}
}
else
break;
return 0;}