Pagini recente » Cod sursa (job #2490213) | Cod sursa (job #2150646) | Cod sursa (job #3161380) | Cod sursa (job #1061301) | Cod sursa (job #1163242)
#include<cstdio>
#include<vector>
#include<queue>
#include<fstream>
using namespace std;
ifstream in("sate.in");
ofstream out("sate.out");
struct muchie { int nod, cost; };
const int nmax = 30009;
vector <muchie> v[nmax];
int n, m, x, y;
int vdist[nmax];
bool poz[nmax];
inline muchie str_ret ( int b, int c ) {
muchie sol;
sol.nod = b;
sol.cost = c;
return sol;
}
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].nod ] == 0 ) {
poz[ v[k][i].nod ] = 1;
vdist[ v[k][i].nod ] = vdist[k] + v[k][i].cost;
q.push( v[k][i].nod );
}
}
}
}
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( str_ret( b, cost ) );
v[b].push_back( str_ret( a, -cost ) );
}
bfs(x);
out<<vdist[y];
return 0;
}