Pagini recente » Cod sursa (job #1287840) | Cod sursa (job #2482078) | Rating Daus Matei (DausMatei) | Rating Iacob Sebastian (Isebi) | Cod sursa (job #1122726)
#include<cstdio>
#include<algorithm>
#define nmax 200005
using namespace std;
struct nod
{
int x;
int y;
int ind;
long long cost;
long long profit;
}v[nmax];
int n,i,j,k,tata[nmax],a,b,rez,m;
int cmp(const nod a,const nod b)
{
if (a.cost==b.cost)
return a.profit<b.profit;
return a.cost<b.cost;
}
int find(int x)
{
if (!tata[x]) return x;
return find(tata[x]);
}
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",&v[i].x,&v[i].y,&v[i].cost,&v[i].profit);
v[i].ind=i;
}
sort(v+1,v+n+1,cmp);
for (i=1;i<=m && n;i++)
{
a=find(v[i].x);
b=find(v[i].y);
if (a!=b)
{
printf("%d ",v[i].ind);
n--;
if (tata[a]>tata[b])
tata[b]=a;else
tata[a]=b;
}
}
return 0;
}