Pagini recente » Cod sursa (job #2690541) | Cod sursa (job #414054) | Cod sursa (job #826754) | Cod sursa (job #3158800) | Cod sursa (job #938873)
Cod sursa(job #938873)
#include <fstream>
#include <vector>
#define Nmax 100004
#define In "sate.in"
#define Out "sate.out"
using namespace std;
vector< pair<short,int> >next[Nmax];
short n,pp,ps,ok = 1;
long long sum[Nmax];
bool viz[Nmax];
void Citire()
{
ifstream f(In);
int m,x,y,c;
f>>n>>m>>pp>>ps;
for(;m;m--)
{
f>>x>>y>>c;
next[x].push_back(make_pair(y,c));
next[y].push_back(make_pair(x,-c));
}
}
inline void Dfs(short nod)
{
viz[nod] = true;
if(nod==ps)
{
return ;
ok = 0;
}
for(vector< pair<short ,int> >::iterator it=next[nod].begin();ok &&it!=next[nod].end();it++)
if(viz[(*it).first]==false)
{
sum[(*it).first] = sum[nod]+(*it).second;
Dfs((*it).first);
}
}
int main()
{
Citire();
Dfs(pp);
ofstream g(Out);
g<<sum[ps]<<"\n";
g.close();
return 0;
}