Pagini recente » fmi-no-stress-2012/clasament | Cod sursa (job #3159620) | Cod sursa (job #1796272) | Cod sursa (job #767147) | Cod sursa (job #543080)
Cod sursa(job #543080)
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const char iname[] = "lazy.in";
const char oname[] = "lazy.out";
const int nmax = 200005;
int i, n, m, father[nmax];
struct muchie
{
int nod1, nod2;
int cl1, cl2, nr;
}mc[nmax];
struct cmp
{
bool operator()(const muchie &a, const muchie &b)const
{
if(a.cl1 < b.cl1)
return 1;
else
if(a.cl1 == b.cl1)
{
if(a.cl2 > b.cl2)
return 1;
return 0;
}
else
return 0;
}
};
int tata(int nod)
{
if(nod == father[nod])
return nod;
father[nod] = tata(father[nod]);
return father[nod];
}
void krusk()
{
for(i = 1; i <= n; i ++)
father[i] = i;
sort(mc + 1, mc + m + 1, cmp());
for(i = 1; i <= n; i ++)
{
if(tata(mc[i].nod1) != tata(mc[i].nod2))
{
printf("%d\n", mc[i].nr);
father[tata(mc[i].nod1)] = father[tata(mc[i].nod2)];
}
}
}
int main()
{
freopen(iname, "r", stdin);
freopen(oname, "w", stdout);
scanf("%d %d", &n, &m);
for(i = 1; i <= n; i ++)
{
scanf("%d %d %d %d", &mc[i].nod1, &mc[i].nod2, &mc[i].cl1, &mc[i].cl2);
mc[i].nr = i;
}
krusk();
return 0;
}