Pagini recente » Cod sursa (job #1742297) | Cod sursa (job #865285) | Cod sursa (job #2108449) | Cod sursa (job #2364676) | Cod sursa (job #1824444)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#define M 100056
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");
vector <int> A[M];
vector <long> cost[M];
queue<int> coada;
int n,m,i,j,x,y,el,G[M];
bool viz[M];
long costf[M];
inline void lee(int x)
{
coada.push(x);
viz[x]=1;
while(!coada.empty())
{
el=coada.front();
coada.pop();
for(int k=0;k<A[el].size();k++)
{
if(viz[A[el][k]]==0)
{
costf[A[el][k]]=costf[A[el][k]]+costf[el]+cost[el][k];
if(A[el][k]==y)
return;
coada.push(A[el][k]);
viz[A[el][k]]=1;
}
}
}
}
int main()
{
int x1,y1,cos;
f>>n>>m>>x>>y;
while(m!=0)
{
f>>x1>>y1>>cos;
A[x1].push_back(y1);
A[y1].push_back(x1);
cost[x1].push_back(cos);
cost[y1].push_back((-1)*cos);
m--;
}
lee(x);
g<<costf[y];
}