Pagini recente » Cod sursa (job #2166613) | Cod sursa (job #1735850) | Cod sursa (job #1964886) | Cod sursa (job #2107503) | Cod sursa (job #2658623)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin( "lazy.in" );
ofstream fout( "lazy.out" );
struct edge {
int a, b;
long long cost1, cost2;
};
const int MaxM = 200002;
const int MaxN = 200002;
edge e[MaxM];
int nxt[MaxN], ind[MaxM];
int cmp( int a, int b ) {
if ( e[a].cost1 < e[b].cost1 ) {
return 1;
} else if ( e[a].cost1 > e[b].cost1 ) {
return 0;
} else {
if ( e[a].cost2 < e[b].cost2 ) {
return 0;
} else {
return 1;
}
}
}
int root( int x ) {
if ( nxt[x] == x ) {
return x;
}
return nxt[x] = root( nxt[x] );
}
void join( int x, int y ) {
nxt[root( x )] = root( y );
}
int main() {
int n, m;
fin >> n >> m;
for ( int i = 0; i < m; ++i ) {
fin >> e[i].a >> e[i].b >> e[i].cost1 >> e[i].cost2;
ind[i] = i;
}
for ( int i = 0; i < n; ++i ) {
nxt[i] = i;
}
sort( ind, ind + m, cmp );
for ( int i = 0; i < m; ++i ) {
if ( root( e[ind[i]].a ) != root( e[ind[i]].b ) ) {
join( e[ind[i]].a, e[ind[i]].b );
fout << ind[i] + 1 << "\n";
}
}
fin.close();
fout.close();
return 0;
}