Pagini recente » Cod sursa (job #3328483) | Cod sursa (job #3242730) | Cod sursa (job #626711) | Diferente pentru problema/log intre reviziile 11 si 9 | Cod sursa (job #3302547)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("sate.in");
ofstream fout ("sate.out");
vector <pair <int,int>> gr[30005];
int vis[30005];
void DFS(int node,int loc,int &ans,int y) {
if (node==y){
ans = loc;
}
vis[node] = 1;
for (auto x:gr[node]){
if (vis[x.first]) continue;
DFS(x.first,loc+x.second,ans,y);
}
}
int main()
{
int n,m,x,y;
fin >> n >> m >> x >> y;
for (int i=1;i<=m;++i){
int I,J,D;
fin >> I >> J >> D;
gr[I].push_back({J,D});
gr[J].push_back({I,-D});
}
int ans = 0;
DFS(x,0,ans,y);
fout << ans;
return 0;
}