Pagini recente » Cod sursa (job #63175) | Cod sursa (job #2133108) | Cod sursa (job #1614676) | Cod sursa (job #155266) | Cod sursa (job #1739829)
#include <bits/stdc++.h>
using namespace std;
struct muchie{
int nod,cost;
};
int n,m,X,Y,d[30003];
vector<muchie>L[30003];
inline void Citire()
{
int i,x,y,c;
muchie w;
ifstream fin("sate.in");
fin>>n>>m>>X>>Y;
for(i=1;i<=m;++i)
{
fin>>x>>y>>c;
w.nod=y;
w.cost=c;
L[x].push_back(w);
w.nod=x;
w.cost=-c;
L[y].push_back(w);
}
fin.close();
}
inline void DFS(int x)
{
unsigned int k;
int y,c;
for(k=0;k<L[x].size();++k)
{
y=L[x][k].nod;
c=L[x][k].cost;
if(d[y]==20000005)
{
d[y]=d[x] + c;
DFS(y);
}
}
}
int main()
{
int i;
Citire();
for(i=1;i<=n;++i)
d[i]=20000005;
d[X]=0;
DFS(X);
ofstream fout("sate.out");
d[Y]=abs(d[Y]);
if(d[Y]==20000005)
while(1)
cout<<".\n";
fout<<d[Y]<<"\n";
return 0;
}