Pagini recente » Monitorul de evaluare | Istoria paginii runda/simulare_oji2012_clasa_a_9-a/clasament | Cod sursa (job #1153653) | Cod sursa (job #1573550) | Cod sursa (job #543927)
Cod sursa(job #543927)
#include <stdio.h>
#include <algorithm>
using namespace std;
#define MAX_N 200010
#define MAX_M 200010
int n, m;
int father[MAX_N], ind[MAX_N];
struct edge {
int x, y, ind;
long long c, p;
} E[MAX_M];
inline int cmp(const edge &A, const edge &B) {
if (A.c != B.c)
return A.c < B.c;
return A.p > B.p;
}
inline int get_father(int x) {
if (x == father[x])
return x;
father[x] = get_father(father[x]);
return father[x];
}
void solve() {
for (int i = 1; i <= n; i++)
father[i] = i;
for (int i = 1; i <= m; i++) {
int t1 = get_father(E[i].x);
int t2 = get_father(E[i].y);
if (t1 != t2) {
printf("%d\n", E[i].ind);
father[t1] = t2;
}
}
}
int main() {
freopen("lazy.in", "r", stdin);
freopen("lazy.out", "w", stdout);
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d %d %lld %lld", &E[i].x, &E[i].y, &E[i].c, &E[i].p);
E[i].ind = i;
}
sort(E + 1, E + m + 1, cmp);
solve();
return 0;
}