Pagini recente » Cod sursa (job #637898) | Cod sursa (job #3185791) | Cod sursa (job #1893953) | Cod sursa (job #230040) | Cod sursa (job #1650184)
#include <bits/stdc++.h>
using namespace std;
ifstream in("sate.in");
ofstream out("sate.out");
const int Nmax=30010;
#define pb push_back
int L[Nmax],n,m,x,y,c1,a,b;
vector< pair < int,int > > G[100025];
deque<int> q;
bool viz[Nmax];
void bfs(){
int node;
viz[x]=1;
while(!q.empty()){
node=q.front();
q.pop_front();
for(int i=0;i<G[node].size();i++){
if(!viz[G[node][i].first]){
if(G[node][i].first > node)
L[G[node][i].first] = L[node] + G[node][i].second;
else
L[G[node][i].first] = L[node] - G[node][i].second;
q.pb(G[node][i].first);
viz[G[node][i].first]=1;
}
}
}
}
int main(){
in>>n>>m>>x>>y;
for(int i=1;i<=n;i++){
L[i]=Nmax;
}
L[x]=0;
for(int i=1;i<=m;i++){
in>>a>>b>>c1;
G[a].pb({b,c1});
G[b].pb({a,c1});
}
q.pb(x);
bfs();
out<<L[y];
return 0;
}