Pagini recente » Cod sursa (job #2209193) | Cod sursa (job #1236550) | Cod sursa (job #2732615) | Cod sursa (job #876173) | Cod sursa (job #1163209)
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
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(){
freopen("sate.in","r",stdin);
freopen("sate.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&x,&y);
for(int i = 0; i<m; ++i)
{
int a, b, cost;
scanf("%d%d%d", &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);
printf("%d", vdist[y]);
return 0;
}