Pagini recente » Cod sursa (job #932719) | Cod sursa (job #726080) | Cod sursa (job #22762) | Cod sursa (job #1173046) | Cod sursa (job #2308478)
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
int n,m,x,y;
bool V[30010];
vector <pair<int,int> > A[30010];
pair<int,int> p;
ifstream fin("sate.in");
ofstream fout("sate.out");
int BFS(int x, int y){
queue <pair<int,int> > q;
p.F=x;p.S=0;
q.push(p);
int pn=0,s=0;
while(!q.empty()){
int cn=q.front().F;
if(cn<pn)s-=q.front().S;
else s+=q.front().S;
if(cn==y)return s;
for(int i=0;i<A[cn].size();i++){
if(!V[A[cn][i].F])q.push(A[cn][i]);
}
V[cn]=1;
if(!q.empty())q.pop();
pn=cn;
}
return s;
}
int main(){
fin>>n>>m>>x>>y;
memset(V,0,n);
for(int i=0;i<m;i++){
int xc,yc,vc;
cin>>xc>>yc>>vc;
p.F=yc;p.S=vc;
A[xc].push_back(p);
p.F=xc;
A[yc].push_back(p);
}
fout<<BFS(x,y);
return 0;
}