Pagini recente » Cod sursa (job #2988449) | Cod sursa (job #509021) | Cod sursa (job #1523363) | Cod sursa (job #3325572) | Cod sursa (job #1560493)
#include <bits/stdc++.h>
#define nmax 200005
using namespace std;
struct Muchie
{
int x, y, ind;
long long c1, c2;
};
Muchie a[nmax];
int n, m, t[nmax];
inline int FindRoot(int i)
{
int k, rad;
rad = i;
while (t[rad] != 0)
rad = t[rad];
while (i != rad)
{
k = t[i];
t[i] = rad;
i = k;
}
return rad;
}
inline void Union(int i, int j)
{
t[j] = i;
}
void Citire()
{
int i;
ifstream fin("lazy.in");
fin >> n >> m;
for (i = 1; i <= m; ++i)
{
fin >> a[i].x >> a[i].y >> a[i].c1 >> a[i].c2;
a[i].ind = i;
}
}
inline bool Cmp(const Muchie A, const Muchie B)
{
if (A.c1 == B.c1)
return A.c2 > B.c2;
return A.c1 < B.c1;
}
void APM()
{
int i, p, q;
ofstream fout("lazy.out");
for (i = 1; i <= m; ++i)
{
p = FindRoot(a[i].x);
q = FindRoot(a[i].y);
if (p != q)
{
fout << a[i].ind << "\n";
Union(p, q);
}
}
fout.close();
}
int main()
{
Citire();
sort(a + 1, a + m + 1, Cmp);
APM();
return 0;
}