Pagini recente » Cod sursa (job #911248) | Cod sursa (job #827363) | Cod sursa (job #1538006) | Cod sursa (job #1248926) | Cod sursa (job #793735)
Cod sursa(job #793735)
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
#define nmax 200010
struct data
{
int X, Y;
long long C, P;
}V[nmax];
int Rank[nmax], Father[nmax], ind[nmax], N, M;
int Find(int X)
{
if(X != Father[X]) X = Find(Father[X]);
return X;
}
void Merge(int X, int Y)
{
if(Rank[X] > Rank[Y]) Father[Y] = X;
else Father[X] = Y;
if(Rank[X] == Rank[Y]) Rank[Y] ++;
}
bool cmp(int i, int j)
{
if(V[i].C == V[j].C) return V[i].P > V[j].P;
return V[i].C < V[j].C;
}
int main()
{
freopen("lazy.in", "r", stdin);
freopen("lazy.out", "w", stdout);
int i;
scanf("%i %i", &N, &M);
for(i = 1; i <= M; i++)
scanf("%i %i %lld %lld", &V[i].X, &V[i].Y, &V[i].C, &V[i].P), ind[i] = i;
sort(ind + 1, ind + M + 1, cmp);
for(i = 1; i <= N; i++)
Rank[i] = 1, Father[i] = i;
for(i = 1; i <= M; i++)
{
if(Find(V[ind[i]].X) != Find(V[ind[i]].Y))
{
Merge(Find(V[ind[i]].X), Find(V[ind[i]].Y));
printf("%i\n", ind[i]);
}
}
return 0;
}