Pagini recente » Rating Ciovnicu Denis (leelcheese) | Cod sursa (job #1072577) | Cod sursa (job #906141) | Cod sursa (job #1310091) | Cod sursa (job #1876669)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("sate.in") ;
ofstream fout("sate.out");
struct str {
int x, y;
};
const int nmax=30000;
vector <str> g[nmax+1];
int sol[nmax+1];
void dfs (int x) {
for (int i=0; i<g[x].size(); i++) {
if (sol[g[x][i].x]==0) {
sol[g[x][i].x]=sol[x]+g[x][i].y;
dfs(g[x][i].x);
}
}
}
int main () {
int n, m, a, b;
fin>>n>>m>>a>>b;
for (int i=1; i<=m; i++) {
int x, y, c;
fin>>x>>y>>c;
str aux;
aux.x=y;
aux.y=c;
g[x].push_back(aux);
aux.x=x;
aux.y=-c;
g[y].push_back(aux);
}
sol[a]=3e7;
dfs(a);
fout<<sol[b]-sol[a]<<"\n";
return 0;
}