Pagini recente » Cod sursa (job #2723453) | Cod sursa (job #3242707) | Cod sursa (job #2640157) | Cod sursa (job #2329754) | Cod sursa (job #2972601)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fin ("lazy.in");
ofstream fout ("lazy.out");
const int NMAX=4e5+5;
int t[NMAX];
int p[NMAX];
struct elem{
int x;
int y;
long long c1;
long long c2;
int ind;
bool operator<(const elem p) const{
if(c1==p.c1)
return c2>p.c2;
return c1<p.c1;
}
}apm[NMAX];
int root(int x)
{
if(t[x]==x)
return x;
return t[x]=root(t[x]);
}
void solve(int x,int y)
{
t[root(y)]=root(x);
}
int main()
{
int n,m,i,j,s=0;
fin>>n>>m;
for(i=1;i<=n;i++)
t[i]=i;
for(i=1;i<=m;i++)
{
fin>>apm[i].x>>apm[i].y>>apm[i].c1>>apm[i].c2;
apm[i].ind=i;
}
sort(apm+1,apm+m+1);
for(i=1;i<=m;i++)
{
if(root(apm[i].x)!=root(apm[i].y))
{
solve(root(apm[i].x),root(apm[i].y));
fout<<apm[i].ind<<"\n";
}
}
return 0;
}