Pagini recente » Cod sursa (job #2369917) | Cod sursa (job #1361275) | Cod sursa (job #157083) | Cod sursa (job #550079) | Cod sursa (job #552440)
Cod sursa(job #552440)
#include<stdio.h>
#include<vector>
#define input "sate.in"
#define output "sate.out"
#define NMAX 30001
using namespace std;
bool been_there_done_that[NMAX];
int n,m,x,y;
vector<vector<pair<int, int> > >G;
void open()
{
freopen(input,"r",stdin);
freopen(output,"w",stdout);
}
void _where_the_magic_happens(int x, int d)
{
if( x == y )
{
printf("%d\n",d);
return;
}
for( int i=1;i<G[x].size();i++)
if( !been_there_done_that[G[x][i].first] )
{
been_there_done_that[G[x][i].first]=true;
_where_the_magic_happens( G[x][i].first,d+G[x][i].second);
}
}
void read()
{
int a,b,d;
scanf("%d%d%d%d",&n,&m,&x,&y);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&a,&b,&d);
G[a].push_back(make_pair(b,d));
G[a].push_back(make_pair(a,-d));
}
}
int main()
{
open();
read();
_where_the_magic_happens(x,0);
return 0;
}