Pagini recente » Cod sursa (job #1025581) | Cod sursa (job #1727733) | Cod sursa (job #645833) | Cod sursa (job #2068836) | Cod sursa (job #1163223)
#include<cstdio>
#include<vector>
#include<queue>
#include<fstream>
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;
int vdist[nmax];
bool poz[nmax];
void bfs( int n ) {
queue <int> q;
poz[n] = 1;
q.push( n );
while ( !q.empty() ) {
int k = q.front();
q.pop();
for ( int i = 0; i < (int)v[k].size(); ++ i ) {
if ( poz[ v[k][i] ] == 0 ) {
poz[ v[k][i] ] = 1;
vdist[ v[k][i] ] = vdist[k] + vcost[k][i];
q.push( v[k][i] );
}
}
}
}
int main(){
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);
}
bfs(x);
out<<vdist[y];
return 0;
}