Pagini recente » Cod sursa (job #350314) | Cod sursa (job #2187437) | Cod sursa (job #2562013) | Cod sursa (job #955608) | Cod sursa (job #628789)
Cod sursa(job #628789)
#include<cstdio>
#include<queue>
#include<vector>
struct ORAS
{
long w,d;
};
using namespace std;
int main () {
long n,m,x,y,i,a,b,dist;
vector <ORAS> t[30004];
vector <ORAS> :: iterator it;
queue<ORAS> q;
ORAS temp,temp2;
freopen("sate.in","r",stdin);
freopen("sate.out","w",stdout);
scanf("%ld%ld%ld%ld",&n,&m,&x,&y);
for (i=1;i<=m;i++)
{
scanf("%ld%ld%ld",&a,&b,&dist);
temp.w=b;
temp.d=dist;
t[a].push_back(temp);
temp.w=a;
t[b].push_back(temp);
}
temp.w=x;
temp.d=0;
q.push(temp);
while (!q.empty()) {
temp=q.front();
for (it=t[temp.w].end()-1;it>=t[temp.w].begin();--it) {
temp2.w=(*it).w;
temp2.d=(*it).d;
if (temp.w>temp2.w)
temp2.d=temp.d-temp2.d;
else
temp2.d=temp.d+temp2.d;
if (temp2.w==y)
{
printf("%ld\n",temp2.d);
break;
}
t[temp.w].pop_back();
q.push(temp2);
}
q.pop();
}
return 0;
}