Pagini recente » CineSeTrezesteDeDimineataDoarmePutin | Cod sursa (job #2355945) | Cod sursa (job #1256371) | Cod sursa (job #607055) | Cod sursa (job #1053800)
#include <fstream>
#include <cstring>
#include <cstdlib>
#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];
char *buffer;
inline void Init_buffer()
{
ifstream f(In);
f.seekg(0,ios::end);
int lg = f.tellg();
f.seekg(0,ios::beg);
buffer = (char*)malloc(lg);
f.getline(buffer,lg,NULL);
f.close();
}
template <class T>
void Citeste(T &x)
{
while(*buffer<'0'||'9'<*buffer)
buffer++;
x = 0;
while('0'<=*buffer && *buffer <='9')
x = x*10+*buffer-'0',buffer++;
}
inline void Citire()
{
ifstream f(In);
int m,x,y,c;
Citeste(n);Citeste(m);
Citeste(pp);Citeste(ps);
for(;m;m--)
{
Citeste(x);Citeste(y);Citeste(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()
{
Init_buffer();
Citire();
Dfs(pp);
ofstream g(Out);
g<<sum[ps]<<"\n";
g.close();
return 0;
}