Pagini recente » Borderou de evaluare (job #1551182) | Cod sursa (job #2346817) | Cod sursa (job #1943118) | Cod sursa (job #435374) | Cod sursa (job #761898)
Cod sursa(job #761898)
#include <cstdio>
#include <algorithm>
using namespace std;
#define nmax 200004
#define ll long long
int n, m, rez[nmax];
typedef struct{
int x, y, poz;
ll c1, c2;
}camp;
camp v[nmax];
int t[nmax];
bool cmp(camp a, camp b){
if (a.c1 == b.c1){
return a.c2 > b.c2;
}
return a.c1 < b.c1;
}
void citeste(){
scanf("%d%d\n", &n, &m);
for(int i=1; i<=m; i++){
//f >> v[i].x >> v[i].y >> v[i].c1 >> v[i].c2;
scanf("%d%d%d%d\n", &v[i].x, &v[i].y, &v[i].c1, &v[i].c2);
v[i].poz = i;
}
sort(v+1, v+m+1, cmp);
}
inline int radacina(int x){
int cpy = x;
for(;t[x]!=0;x=t[x]);
for(;cpy!=x;){
int temp = cpy;
t[cpy] = x;
cpy = t[temp];
}
return x;
}
void uneste(int x, int y){
t[x] = y;
}
void rezolva(){
for(int i=1; i<=m; i++){
int X = radacina(v[i].x);
int Y = radacina(v[i].y);
if (X == Y) continue;
uneste(X,Y);
rez[++rez[0]] = v[i].poz;
}
//for(int i=1; i<n; i++) cout << rez[i] << "\n";
for(int i=1; i<n; i++) printf("%d\n", rez[i]);
}
int main(){
freopen("lazy.in", "r" ,stdin);
freopen("lazy.out", "w", stdout);
citeste();
rezolva();
fclose(stdin);
fclose(stdout);
return 0;
}