Pagini recente » Cod sursa (job #2966532) | Cod sursa (job #820327) | Cod sursa (job #2799642) | Cod sursa (job #991942) | Cod sursa (job #2937680)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lazy.in");
ofstream fout("lazy.out");
struct edge_t {
int u, v, c1, c2, index;
void read() {
fin >> u >> v >> c1 >> c2;
}
bool operator < (const edge_t &rhs) const {
if (c1 != rhs.c1) {
return c1 < rhs.c1;
}
return c2 > rhs.c2;
};
};
struct DSU {
vector<int> p, sz;
DSU(int n) {
p.resize(n + 1);
iota(p.begin(), p.end(), 0);
sz.assign(n + 1, 1);
}
int root(int x) {
if (x == p[x]) {
return x;
}
return p[x] = root(p[x]);
}
bool unite(int u, int v) {
int x = root(u), y = root(v);
if (x == y) {
return false;
}
if (sz[y] < sz[x]) {
swap(x, y);
}
p[x] = y;
sz[y] += sz[x];
return true;
}
};
int main() {
int n, m;
fin >> n >> m;
vector<edge_t> edges(m);
for (int i = 0; i < m; ++i) {
edges[i].read();
edges[i].index = i + 1;
}
DSU dsu(n);
sort(edges.begin(), edges.end());
for (auto e : edges) {
if (dsu.unite(e.u, e.v)) {
fout << e.index << '\n';
}
}
fin.close();
fout.close();
return 0;
}