Pagini recente » Cod sursa (job #1928090) | Profil RolandPetrean | Cod sursa (job #1287316) | Cod sursa (job #1351029) | Cod sursa (job #2039835)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("lazy.in");
ofstream g("lazy.out");
int n, m, rx, ry, t[400001], s, k, p[400001], u[400001];
struct nod
{
long long cost1;
long long cost2;
int dr;
int st;
int poz;
} l[400010];
bool cmp(nod x, nod y)
{
if(x.cost1==y.cost1)
return x.cost2>y.cost2;
return x.cost1<y.cost1;
}
int rad (int x)
{
while(t[x]>0)
x=t[x];
return x;
}
int main()
{
f>>n>>m;
for(int i=1;i<=n;i++)
t[i]=-1;
for(int i=1;i<=m;i++)
{
f>>l[i].st>>l[i].dr>>l[i].cost1>>l[i].cost2;
l[i].poz=i;
}
sort(l+1, l+m+1, cmp);
for(int i=1;i<=m;i++)
{
rx=rad(l[i].st);
ry=rad(l[i].dr);
if(rx!=ry)
{
p[++k]=l[i].poz;
if(t[rx]<t[ry])
{
t[rx]+=t[ry];
t[ry]=rx;
}
else
{
t[ry]+=t[rx];
t[rx]=ry;
}
}
}
for(int i=1;i<=k;i++)
g<<p[i]<<"\n";
return 0;
}