Pagini recente » Cod sursa (job #488524) | Cod sursa (job #2456971) | Cod sursa (job #555480) | Cod sursa (job #621808) | Cod sursa (job #543543)
Cod sursa(job #543543)
//first kill
#include <stdio.h>
#include <algorithm>
#define NMAX 200005
#define ll long long
using namespace std;
struct muchie{int a,b,e; ll c,d;};
muchie A[NMAX];
int n,m,root[NMAX],sol[NMAX],r;
void read()
{
scanf("%d%d",&n,&m);
int i;
for (i=1; i<=m; i++)
{
scanf("%d%d%lld%lld",&A[i].a,&A[i].b,&A[i].c,&A[i].d);
A[i].e=i;
}
}
bool comp(muchie x,muchie y)
{
if (x.c<y.c)
return 1;
if (x.c>y.c)
return 0;
if (x.d>y.d)
return 1;
return 0;
}
void init()
{
int i;
for (i=1; i<=n; i++)
root[i]=i;
}
int find_root(int nod)
{
int nod2=nod,act;
while (root[nod2]!=nod2)
nod2=root[nod2];
while (root[nod]!=nod)
{
act=root[nod];
root[nod]=nod2;
nod=act;
}
return nod2;
}
void uneste(int nod1,int nod2)
{
root[nod1]=nod2;
}
void solve()
{
init();
int i;
for (i=1; i<=m; i++)
if (find_root(A[i].a)!=find_root(A[i].b))
{
uneste(find_root(A[i].a),find_root(A[i].b));
sol[++r]=A[i].e;
}
sort(sol+1,sol+r+1);
for (i=1; i<=r; i++)
printf("%d\n",sol[i]);
}
int main()
{
freopen("lazy.in","r",stdin);
freopen("lazy.out","w",stdout);
read();
sort(A+1,A+m+1,comp);
solve();
return 0;
}