Pagini recente » Cod sursa (job #3190271) | Cod sursa (job #2205340) | Cod sursa (job #2954600) | Cod sursa (job #1954574) | Cod sursa (job #1163175)
#include<fstream>
#include<vector>
using namespace std;
ifstream in("sate.in");
ofstream out("sate.out");
const int nmax = 30009;
vector <int> v[nmax], vcost[nmax];
int n, m, x, y;
long long rasp, act, vdist[nmax];
bool poz[nmax];
void dfs(int x)
{
poz[x] = 1;
vdist[x] = act;
for(int i = 0; i<v[x].size(); i++)
{
if(!poz[v[x][i]])
{
act = act + vcost[x][i];
dfs(v[x][i]);
}
}
}
int main(){
int player_unu=0;
in>>n>>m>>x>>y;
for(int i = 0; i<m; i++)
{
int a, b, cost;
in>>a>>b>>cost;
v[a].push_back(b);
v[b].push_back(a);
vcost[a].push_back(cost);
vcost[b].push_back(-cost);
}
dfs(x);
out<<vdist[y] - vdist[x];
return player_unu;
}