Pagini recente » Cod sursa (job #2956617) | Cod sursa (job #743169) | Cod sursa (job #97220) | Cod sursa (job #755002) | Cod sursa (job #1824396)
#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,t,l,x,y,el,G[M];
long costf[M];
void lee(int x)
{
coada.push(x);
while(!coada.empty())
{
el=coada.front();
coada.pop();
for(int k=0;k<G[el];k++)
{
if(A[el][k]!=0)
{
costf[A[el][k]]=costf[A[el][k]]+costf[el]+cost[el][k];
coada.push(A[el][k]);
for(int k1=0;k1<A[A[el][k]].size();k1++)
{
if(A[A[el][k]][k1]==el)
{
A[A[el][k]][k1]=0;
break;
}
}
A[el][k]=0;
}
}
}
}
int main()
{
int x1,y1,cos;
f>>n>>m>>x>>y;
while(m!=0)
{
f>>x1>>y1>>cos;
A[x1].push_back(y1);
int inv=(-1)*cos;
A[y1].push_back(x1);
cost[x1].push_back(cos);
cost[y1].push_back(inv);
m--;
}
for(i=1;i<=n;i++)
G[i]=A[i].size();
lee(x);
g<<costf[y];
}