Pagini recente » Cod sursa (job #2586016) | Cod sursa (job #2406224) | Cod sursa (job #2399655) | Cod sursa (job #2972269) | Cod sursa (job #2406304)
#include <cstdio>
#include <algorithm>
using namespace std;
const int NMAX = 2 * 1000 * 100;
const int MMAX = 2 * 1000 * 100;
int dad[NMAX + 2], s[NMAX + 1];
struct lol{
int a, b, poz;
long long c1, c2;
};
lol v[MMAX + 1];
int myfind( int a ){
if( a == dad[a] )
return a;
dad[a] = myfind(dad[a]);
return dad[a];
}
void unite( int a, int b, int ok ){
if( ok == 0 ) //nu am calculat find(a)
dad[myfind(a)] = myfind(b);
else
dad[a] = b;
}
bool cmp( lol X, lol Y ){
if( X.c1 == Y.c1 )
return X.c2 > Y.c2;
return X.c1 < Y.c1;
}
int main()
{
int n, m, x, y, k, i;
FILE *fin, *fout;
fin = fopen( "lazy.in", "r" );
fout = fopen( "lazy.out", "w" );
fscanf( fin, "%d%d", &n, &m );
for( i = 0; i < m; ++i ){
fscanf( fin, "%d%d%lld%lld", &v[i].a, &v[i].b, &v[i].c1, &v[i].c2 );
v[i].poz = i + 1;
}
sort( v, v + m, cmp );
for( i = 0; i <= n; ++i )
dad[i] = i;
k = 0;
for( i = 0; i < m; ++i ){
if( (x = myfind(v[i].a)) != (y = myfind(v[i].b)) ){
s[k++] = v[i].poz;
unite( x, y, 1 );
}
}
for( i = 0; i < n - 1; ++i )
fprintf( fout, "%d\n", s[i] );
fclose( fin );
fclose( fout );
return 0;
}