Cod sursa(job #1553814)

Utilizator elevenstrArina Raileanu elevenstr Data 20 decembrie 2015 16:03:43
Problema Lazy Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <bits/stdc++.h>

using namespace std;
//http://www.infoarena.ro/problema/lazy
#define MAX 400000
long long tt[MAX];
FILE* fila=fopen("lazy.in","r");
ofstream out("lazy.out");
struct muchie
{
   long long x,y,ind;
    long long cost,profi;
}mu[MAX];
bool cmp1(muchie a, muchie b)
{
    return ((a.cost<b.cost)||(a.cost==b.cost&&a.profi>b.profi));
}
vector<long long> v;
const int LIM=4000;
char buff[LIM];
int poz=0;
void cit(long long &x)
{  while(!isdigit(buff[poz]))
{
   ++poz;
    if(poz==LIM)
    {
        poz=0;
        fread(buff,1,LIM,fila);
    }
}
   x=0;
   while(isdigit(buff[poz]))
   {
       x=x*10+buff[poz]-'0';
       ++poz;
       if(poz==LIM)
        {
        poz=0;
        fread(buff,1,LIM,fila);
        }
   }
}
long long find_t(long long x)
{
    if(tt[x]==x)
        return x;
    long long t=find_t(tt[x]);
    tt[x]=t;
    return t;
}
int main()
{   long long n,m;
    cit(n);cit(m);
    for(int i=1;i<=m;i++)
    {
        cit(mu[i].x);
        cit(mu[i].y);
        cit(mu[i].cost);
        cit(mu[i].profi);
        mu[i].profi=1LL*mu[i].profi*mu[i].cost;
        mu[i].ind=i;
    }
    for(int i=1;i<=n;i++)
        tt[i]=i;
    sort(mu+1,mu+m+1,cmp1);
    for(int i=1;i<=m;i++)
        if(find_t(mu[i].x)!=find_t(mu[i].y))
        {  tt[find_t(mu[i].x)]=find_t(mu[i].y);
           v.push_back(mu[i].ind);
        }
    while(!v.empty())
    {
        out<<v.back()<<'\n';
        v.pop_back();
    }
    return 0;
}