Cod sursa(job #1307445)

Utilizator ArchazeyBaltatu Andrei-Mircea Archazey Data 2 ianuarie 2015 12:09:17
Problema Lazy Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.72 kb
#include<bits/stdc++.h>
using namespace std;

struct cell
{
    int x,ind;
    long long c1,c2;
    bool operator <(const cell &e ) const
        {
            if (c1==e.c1) return c2>e.c2;
            return c1>e.c1;
        }
};

ifstream fin("lazy.in");
ofstream fout("lazy.out");

const int NMAX=200005;

int n,m,muchie[NMAX];
long long b[NMAX],c[NMAX];
vector<cell>v[NMAX];
vector<cell>::iterator it;
priority_queue<cell>Q;
bitset<NMAX>viz;
bitset<NMAX>vizoi;

int main()
{
    int i,aux;
    cell k;
    fin>>n>>m;
    for (i=1;i<=m;i++)
        {
            k.ind=i;
            fin>>aux>>k.x>>k.c1>>k.c2;
            v[aux].push_back(k);
            swap(k.x,aux);
            v[aux].push_back(k);
        }
    for (it=v[1].begin();it!=v[1].end();it++)
        Q.push(*it);
    viz[1]=1;
    while (!Q.empty())
        {
            k=Q.top();
            Q.pop();
            if (!viz[k.x])
                {
                    viz[k.x]=1;
                    vizoi[k.ind]=1;
                    muchie[k.x]=k.ind;
                    b[k.x]=k.c1;
                    c[k.x]=k.c2;
                    //pun muchiile
                    for (it=v[k.x].begin();it!=v[k.x].end();it++) Q.push(*it);
                }
            else if (viz[k.x]!=0 && vizoi[k.ind]==0)
                {
                    if (k.c1==b[k.x] && k.c2>c[k.x])
                        {
                            vizoi[k.ind]=1;
                            vizoi[muchie[k.x]]=0;
                            muchie[k.x]=k.ind;
                            c[k.x]=k.c2;
                        }
                }
        }
    for (i=1;i<=m;i++)
        if (vizoi[i]!=0) fout<<i<<"\n";
    return 0;
}