Pagini recente » Cod sursa (job #1283537) | Cod sursa (job #517145) | Cod sursa (job #1615684) | Cod sursa (job #1524694) | Cod sursa (job #2937488)
#include <bits/stdc++.h>
#define N 200005
using namespace std;
ifstream fin("lazy.in");
ofstream fout("lazy.out");
int n, m;
vector<int>t;
struct edge {
int x, y, ind;
long long o, p;
bool operator <(const edge A) const {
if (o == A.o)
return p > A.p;
return o < A.o;
}
}g[N];
void read() {
fin >> n >> m;
t.resize(n + 5);
for (int i = 1; i <= m; ++i) {
fin >> g[i].x >> g[i].y >> g[i].o >> g[i].p;
g[i].ind = i;
}
}
int Find(int x) {
int root = x,y;
while (t[root])
root = t[root];
while (x != root) {
y = t[x];
t[x] = root;
x = y;
}
return root;
}
void Union(int x, int y) {
t[y] = x;
}
void solve() {
sort(g + 1, g + m + 1);
for (int i = 1; i <= m; ++i) {
int r1 = Find(g[i].x), r2 = Find(g[i].y);
if (r1 != r2) {
Union(r1, r2);
fout << g[i].ind << "\n";
}
}
}
int main() {
read();
solve();
return 0;
}