Pagini recente » Cod sursa (job #668132) | Cod sursa (job #2658573) | Cod sursa (job #419884) | Cod sursa (job #254486) | Cod sursa (job #2529237)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lazy.in");
ofstream fout("lazy.out");
struct Muchie
{
long long x, y, ind;
long long cost, profit;
};
Muchie a[200005];
long long n, m, t[200005], ans[200005], k;
bool Cmp(Muchie A, Muchie B)
{
if(A.cost == B.cost) return A.profit > B.profit;
return A.cost < B.cost;
}
void Union(long long x, long long y)
{
t[y] = x;
}
long long Find(long long x)
{
long long rad = x, y;
while(t[rad])
rad = t[rad];
while(x != rad)
{
y = t[x];
t[x] = rad;
x = y;
}
return rad;
}
void Kruskal()
{
for(int i = 1; i <= m; i++)
{
long long x, y;
x = Find(a[i].x);
y = Find(a[i].y);
if(x != y)
{
Union(x, y);
ans[++k] = a[i].ind;
}
}
for(int i = 1; i <= k; i++)
fout << ans[i] << "\n";
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= m; i++)
{
long long x;
fin >> a[i].x >> a[i].y >> a[i].cost >> a[i].profit;
a[i].ind = i;
}
sort(a + 1, a + m + 1, Cmp);
Kruskal();
return 0;
}