Cod sursa(job #2378207)

Utilizator gheorghita.pavelGheorghita Pavel gheorghita.pavel Data 11 martie 2019 20:58:49
Problema Sate Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>
	
#include <stdlib.h>
using namespace std;
 
 
struct drum
{
    int nod,cost;
} var1,var2;
 
int viz [40001];
int n,x,y,cost;
vector<drum>v[100050];
void dfs ( int nod )
{
    if(nod==y)
    {
        cout<<cost;
        return;
    }
    viz[nod]=-1;
    for(int i=0; i<v[nod].size(); i++)
        if(viz[v[nod][i].nod]==0)
        {
            cost+=v[nod][i].cost;
            dfs(v[nod][i].nod);
            cost-=v[nod][i].cost;
        }
}
 
 
ifstream fin("sate.in");
ofstream fout("sate.out");
 
int main()
{
    int i,m,a,b,dist;
    fin>>n>>m>>x>>y;
    for(i=1; i<=m; i++)
    {
        fin>>a>>b>>dist;
        var1= {b,dist};
        var2= {a,-dist};
        v[a].push_back(var1);
        v[b].push_back(var2);
    }
    dfs(x);
    return 0;
}