Cod sursa(job #1824439)

Utilizator GeoeyMexicanuBadita George GeoeyMexicanu Data 7 decembrie 2016 20:43:25
Problema Sate Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#define M 100056

using namespace std;

ifstream f("sate.in");
ofstream g("sate.out");

vector <int> A[M];
vector <long> cost[M];
queue<int> coada;
int n,m,i,j,t,l,x,y,el,G[M];
bool viz[M];
long costf[M];
inline void lee(int x)
{
    coada.push(x);
    viz[x]=1;
    while(!coada.empty())
    {
        el=coada.front();
        coada.pop();
        for(int k=0;k<A[el].size();k++)
        {
            if(viz[A[el][k]]==0)
            {
                costf[A[el][k]]=costf[A[el][k]]+costf[el]+cost[el][k];
                if(A[el][k]==y)
                    return;
                coada.push(A[el][k]);
                viz[A[el][k]]=1;
            }
        }
    }
}
int main()
{
    int x1,y1,cos;
    f>>n>>m>>x>>y;
    while(m!=0)
    {
        f>>x1>>y1>>cos;
        A[x1].push_back(y1);
        int inv=(-1)*cos;
        A[y1].push_back(x1);
        cost[x1].push_back(cos);
        cost[y1].push_back(inv);
        m--;
    }
    lee(x);
    g<<costf[y];
}