Cod sursa(job #1253151)

Utilizator Pintilie_AndreiFII-Pintilie Andrei Pintilie_Andrei Data 31 octombrie 2014 20:39:15
Problema Sate Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#define N 30005
#define oo 200000000
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
struct str
{
    int nod,cost;
};
vector<str> a[N];
queue <int> q;
int d[N],v[N];

int n,m,start,stop;
void Read()
{
    fin>>n>>m>>start>>stop;
    int i,j,x,y,c;
    str w;
    for(i=1; i<=m; i++)
    {
        fin>>x>>y>>c;
        w.nod=y;
        w.cost=c;
        a[x].push_back(w);
        w.nod=x;
        w.cost=c*-1;
        a[y].push_back(w);

    }

}

void Rez()
{
    int i;
    for(i=1; i<=n; i++)
        d[i]=oo;
    d[start]=0;
        int w;
        str x;
    q.push(start);

    while(!q.empty())
    {
        w=q.front();
        q.pop();
       // v[w]=0;
        for(i=0; i<a[w].size(); i++)
        {
            x=a[w][i];
            if(v[x.nod]==0)
            {
            d[x.nod]=d[w]+x.cost;
                q.push(x.nod);
                v[x.nod]=1;
            if(x.nod==stop) return ;
            }
        }

    }


}

int main()
{
    Read();
    Rez();
    fout<<d[stop];
    return 0;
}