Pagini recente » Cod sursa (job #2790988) | Cod sursa (job #995262) | Cod sursa (job #1516032) | Cod sursa (job #2570569) | Cod sursa (job #541436)
Cod sursa(job #541436)
#include<stdio.h>
#include<algorithm>
#define Nmax 201010
using namespace std;
struct cel
{
int ind,x,y;
long long c1,c2;
}v[Nmax];
bool cmp(cel a, cel b)
{
if(a.c1==b.c1)
{
return a.c2>b.c2;
}
else
return a.c1<b.c1;
}
int tata[201010],tip,h[201010];
int find(int x)
{
int R,y;
R=x;
while(tata[R]!=R)
R=tata[R];
while(tata[x]!=x)
{
y=tata[x];
tata[x]=R;
x=y;
}
return R;
}
int unite(int x,int y)
{
if(h[x]>h[y])
{
tata[y]=x;
}
else tata[x]=y;
if(h[x]==h[y])
h[y]++;
}
int N,M;
int main()
{
freopen("lazy.in","r",stdin);
freopen("lazy.out","w",stdout);
scanf("%d%d",&N,&M);
for(int i=1;i<=M;++i)
{
scanf("%d%d%lld%lld",&v[i].x,&v[i].y,&v[i].c1,&v[i].c2);
v[i].ind=i;
}
sort(v+1,v+N+1,cmp);
for(int i=1;i<=N;++i)
{
tata[i]=i;
}
for(int i=1;i<=M;++i)
{
if(find(v[i].x)!=find(v[i].y))
{
unite(find(v[i].x),find(v[i].y));
printf("%d\n",v[i].ind);
}
}
}