Pagini recente » Monitorul de evaluare | Cod sursa (job #582123) | Cod sursa (job #2355819) | Cod sursa (job #375106) | Cod sursa (job #1838281)
#include <fstream>
#include <vector>
#define VAL 30005
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
int N, M, i, j, x, y;
int a, b, c;
int cost[VAL];
bool parc[VAL];
vector< pair<int, int> > G[VAL];
void dfs(int nod)
{
vector< pair<int, int> > :: iterator it;
parc[nod]=true;
for (it=G[nod].begin(); it!=G[nod].end(); it++)
{
if (parc[it->first]==false)
{
cost[it->first]=cost[nod]+(it->second);
dfs(it->first);
}
}
}
int main()
{
fin >> N >> M >> x >> y;
for (i=1; i<=M; i++)
{
fin >> a >> b >> c;
G[a].push_back(make_pair(b, c));
G[b].push_back(make_pair(a, -c));
}
dfs(x);
fout << cost[y] << '\n';
fin.close();
fout.close();
return 0;
}