Pagini recente » Cod sursa (job #910659) | Cod sursa (job #429488) | Cod sursa (job #2517424) | Cod sursa (job #2323752) | Cod sursa (job #1418618)
#include <iostream>
#include <fstream>
#include <vector>
#define NMax 30005
#define MMax 100030
#define Nod first
#define Value second
using namespace std;
ifstream g("sate.in");
ofstream f("sate.out");
int cost[MMax],uz[NMax],N,M,x,y,z,p1,p2;
vector <pair <int,int> > V[NMax];
void Citire()
{
g>>N>>M;
g>>p1>>p2;
for(int i=1;i<=M;i++)
{
g>>x>>y>>z;
V[x].push_back(make_pair(y,z));
V[y].push_back(make_pair(x,-z));
}
}
void DFS(int x)
{
uz[x]=1;
for(int i=0;i<V[x].size();i++)
{
if(uz[V[x][i].Nod]==0)
{
cost[V[x][i].Nod]=cost[x]+V[x][i].Value;
DFS(V[x][i].Nod);
if(V[x][i].Nod==y)
return;
}
}
}
int main()
{
Citire();
DFS(p1);
f<<cost[p2];
}