Pagini recente » Cod sursa (job #911685) | Cod sursa (job #61911) | Cod sursa (job #900185) | Cod sursa (job #656269) | Cod sursa (job #682557)
Cod sursa(job #682557)
#include<fstream>
#include<cstdlib>
#include<vector>
#define NN 30001
#define pb push_back
using namespace std;
ofstream out("sate.out");
struct QQ{
int vf,cost;
QQ(int v,int c)
{
vf=v;
cost=c;
}
};
vector<QQ>G[NN];
int x,y,n,m,v[NN];
void citire();
void dfs(int ,int );
int main()
{
citire();
dfs(x,0);
return 0;
}
void citire()
{
ifstream in("sate.in");
in>>n>>m>>x>>y;
int i,j,c;
for(;m;m--)
{
in>>i>>j>>c;
G[i].pb(QQ(j,c));
G[j].pb(QQ(i,c));
}
}
void dfs(int start,int d)
{
int i,j;
if(start==y)
{
out<<d<<" ";
exit(0);
}
v[start]=1;
for(i=0;i<G[start].size();i++)
if(v[G[start][i].vf]==0)
if(G[start][i].vf<start)
{
d-=G[start][i].cost;
dfs(G[start][i].vf,d);
d+=G[start][i].cost;
}
else
if(G[start][i].vf>start)
{
d+=G[start][i].cost;
dfs(G[start][i].vf,d);
d-=G[start][i].cost;
}
}