Cod sursa(job #1416231)

Utilizator mambojamboPop Flaviu mambojambo Data 7 aprilie 2015 17:41:22
Problema Sate Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <iostream>
#include <vector>
#define nmax 30005
#define mmax 100030
# define nod first
# define value second

using namespace std;

ifstream f("sate.in");
ofstream g("sate.out");
vector <pair <int,int> > v[nmax];
int cost[mmax],i,n,y,m,x,z,source,dest;
bool seen[nmax];


void dfs(int x)
     {
        seen[x]=true;

        for (int i =0;i<v[x].size();i++)
                {
                    int y=v[x][i].nod;
                    if (!seen[y])
                    {


                                 cost[y]=cost[x]+v[x][i].value;


                        dfs(y);
                        if (y==dest) return;
                    }
                }
     }


int main ()
{
    f>>n>>m;
    f>>source>>dest;

    for(i=1;i<=m;i++)
    {
        f>>x>>y>>z;
        v[x].push_back(make_pair(y,z));
        v[y].push_back(make_pair(x,-z));
    }
    cost[source]=0;

    dfs(source);

    g<<cost[dest];





return 0;
}