Cod sursa(job #2122751)

Utilizator Victor_IonescuVictor Ionescu Victor_Ionescu Data 5 februarie 2018 14:20:33
Problema Politie Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 2.05 kb
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
vector <int> v[250002];
ifstream f("politie.in");
ofstream g("politie.out");
struct el{
    int lin,col,cost,per;
}w[250002];
struct cel{
    int oc,ca;
}viz[250002];
int fr[2500000];
void df()
{
    int pi,ps,coada[250002],i,j,l,x;
    pi=ps=1;
    coada[1]=1;
    l=1;
    while(w[l].lin!=1)
        l++;
    viz[1].oc=w[l].cost;
    viz[1].ca=w[l].per;
    while(pi>=ps)
    {
        x=coada[ps];
            for(j=0;j<v[x].size();j++)
            {
                    l=1;
                    while((w[l].lin!=x||w[l].col!=v[x][j])&&(w[l].lin!=v[x][j]||w[l].col!=x))
                    {
                        l++;
                    }
                    if(viz[v[x][j]].oc>w[l].cost||viz[v[x][j]].oc==0)
                    {
                        viz[v[x][j]].oc=w[l].cost; viz[v[x][j]].ca=w[l].per;
                        coada[++pi]=v[x][j];
                    }
                    else
                    {
                        if(viz[v[x][j]].oc==w[l].cost&&viz[v[x][j]].ca>w[l].per)
                            viz[v[x][j]].ca=w[l].per;
                    }
            }
            ps++;
    }
}
int main()
{
    int n,m,k,p,x,y,cx,xp;
    f>>n>>m>>k>>p;
    for(int i=1;i<=m;i++)
    {
        f>>x>>y>>w[i].cost>>w[i].per;
        w[i].lin=x;
        w[i].col=y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    df();
    cel aux;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(viz[i].oc>viz[j].oc)
            {
                aux=viz[i];
                viz[i]=viz[j];
                viz[j]=aux;
            }
            else
            {
                if(viz[i].oc==viz[j].oc&&viz[i].ca>viz[j].ca)
                {
                    aux=viz[i];
                viz[i]=viz[j];
                viz[j]=aux;
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        g<<viz[i].ca<<endl;
    }
    return 0;
}