Pagini recente » Cod sursa (job #1959772) | Cod sursa (job #2820225) | Cod sursa (job #88736) | Cod sursa (job #1487596) | Cod sursa (job #2850904)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
const string fn = "lazy";
ifstream fin(fn + ".in");
ofstream fout(fn + ".out");
int n, m;
int t[200005];
struct edge {
int x, y, i;
ll cost, profit;
bool operator < (edge const &oth) {
if (cost != oth.cost)
return (cost < oth.cost);
return (profit > oth.profit);
}
};
int Find(int x) {
int rx = x, y;
while (t[rx] != 0) rx = t[rx];
while (x != rx) {
y = t[x];
t[x] = rx;
x = y;
}
return rx;
}
void Union(int x, int y) {
t[y] = x;
}
vector<edge> g;
int main() {
int x, y, cost, profit;
fin >> n >> m;
g.resize(m + 1);
for (int i = 1; i <= m; ++i) {
fin >> g[i].x >> g[i].y >> g[i].cost >> g[i].profit;
g[i].i = i;
}
sort(g.begin() + 1, g.end());
for (int i = 1; i <= m; ++i) {
x = Find(g[i].x);
y = Find(g[i].y);
if (x != y) {
Union(x, y);
fout << g[i].i << '\n';
}
}
fin.close();
fout.close();
return 0;
}