Pagini recente » Cod sursa (job #1312242) | Rating CNITV-Florescu-Pene-Stoian (teamKoch) | Cod sursa (job #897399) | Cod sursa (job #614238) | Cod sursa (job #2653318)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("lazy.in");
ofstream fout ("lazy.out");
struct muchie{
int x, y, cost, profit, indice;
};
bool cmp (muchie a, muchie b){
if (a.cost != b.cost){
return a.cost < b.cost;
}
else{
return a.profit > b.profit;
}
}
muchie v[200005];
int n, m, i, radx, rady, k;
int t[200005], apm[200005];
int radacina (int a){
while (t[a] > 0){
a = t[a];
}
return a;
}
int main(){
fin >> n >> m;
for (i=1; i<=m; i++){
fin >> v[i].x >> v[i].y >> v[i].cost >> v[i].profit;
v[i].indice = i;
v[i].profit *= v[i].cost;
}
sort (v + 1, v + m + 1, cmp);
for (i=1; i<=n; i++){
t[i] = -1;
}
for (i=1; i<=m; i++){
radx = radacina (v[i].x);
rady = radacina (v[i].y);
if (radx == rady){
continue; //ac comp conexa
}
apm[++k] = v[i].indice;
if (t[radx] < t[rady]){
t[radx] += t[rady];
t[rady] = radx;
}
else{
t[rady] += t[radx];
t[radx] = rady;
}
}
for (i=1; i<=k; i++){
fout << apm[i] << "\n";
}
return 0;
}