Cod sursa(job #1122800)

Utilizator dragangabrielDragan Andrei Gabriel dragangabriel Data 25 februarie 2014 20:32:13
Problema Lazy Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstring>
#define nmax 200005
using namespace std;
struct nod
{
    int x;
    int y;
    int ind;
    long long cost;
    long long profit;
}v[nmax];
int n,i,j,k,tata[nmax],a,b,rez,m;
vector<int>sol;

int cmp(const nod a,const nod b)
{
    if (a.cost==b.cost)
        return a.profit<b.profit;
    return a.cost<b.cost;
}

int find(int x)
{
    while(tata[x]!=0) x=tata[x];
    return x;
}

int main()
{
    freopen("lazy.in","r",stdin);
    freopen("lazy.out","w",stdout);
   // scanf("%d %d",&n,&m);
    cin>>n>>m;
    for (i=1;i<=m;i++)
    {
        //scanf("%d %d %lld %lld",&v[i].x,&v[i].y,&v[i].cost,&v[i].profit);
        cin>>v[i].x>>v[i].y>>v[i].cost>>v[i].profit;
        v[i].ind=i;
    }
    sort(v+1,v+m+1,cmp);
    for (i=1;i<=m;i++)
    {
        a=find(v[i].x);
        b=find(v[i].y);
        if (a!=b)
        {
            sol.push_back(v[i].ind);
           /* if (a>b)
                tata[b]=a;else
                    tata[a]=b;*/
            tata[b]=a;
        }
    }
    sort(sol.begin(),sol.end());
    for (int j=0;j<sol.size();j++)
        cout<<sol[j]<<"\n";
        //printf("%d\n",sol[j]);
    return 0;
}