Cod sursa(job #1394113)

Utilizator AlexTAlexandru AlexT Data 20 martie 2015 00:05:59
Problema Sate Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <iostream>
#include <fstream>
#include <vector>
#include<queue>
using namespace std;
int main()
{
int dist[30001],k, j, i, n, m, b, c, x, y, d, vizitat[30001],parinte[30001];
pair<int,int> pereche;
vector< pair <int,int> > v[30001];
queue<int> q;
bool gasit=0;
ifstream f("sate.in");
ofstream g("sate.out");
f >> n >> m >> b >>c;
for(i=0;i<n;i++)
    {
    parinte[i]=vizitat[i]=0;
    }
for(i=0;i<m;i++)
    {
    f >> x >> y >> d;
    v[x].push_back(make_pair(y,d));
    v[y].push_back(make_pair(x,-d));
    }
for(i=0;i<n;i++)
    {
    dist[i]=-9999;
    }
    dist[b]=0;
q.push(b);
while(!q.empty())
{
k=q.front();
q.pop();
for(i=0;i<v[k].size();i++)
    {
    if(dist[v[k][i].first]==-9999)
        {
        dist[v[k][i].first]=dist[k]+v[k][i].second;
        }
    if(v[k][i].first==c)
        {
        g<<dist[v[k][i].first];
        return 0;
        }
    q.push(v[k][i].first);
    }
}
f.close();
g.close();
    return 0;
}