Mai intai trebuie sa te autentifici.

Cod sursa(job #1052589)

Utilizator the@EyE@Postavaru Stefan the@EyE@ Data 11 decembrie 2013 16:33:54
Problema Sate Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include<stdio.h>
#include<vector>
#define INF 30002

using namespace std;

struct edge
{
    int dest,cost;
};

vector<edge> graph[INF];
bool check[INF],ok=false;
int n,m,x,y,ras;

void df(int nod, int d)
{
    if(check[nod])return;
    check[nod]=1;
    if(nod==y){ras=d;ok=true;return;}
    for(int i=0;i<graph[nod].size();++i)
       { df(graph[nod][i].dest,graph[nod][i].cost+d);
         if(ok)return;
       }
}

int main()
{
    freopen("sate.in","r",stdin);
    freopen("sate.out","w",stdout);
    scanf("%d%d%d%d",&n,&m,&x,&y);
    for(int i=0;i<m;++i)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        if(a>b){a=a^b;b=a^b;a=a^b;}
        edge e1;e1.dest=b;e1.cost=c;
        edge e2;e2.dest=a;e2.cost=-c;
        graph[a].push_back(e1);
        graph[b].push_back(e2);
    }
    df(x,0);
    printf("%d\n",ras);
    return 0;
}