Pagini recente » Cod sursa (job #1505565) | Cod sursa (job #62322) | Cod sursa (job #1530310) | Cod sursa (job #346011) | Cod sursa (job #1395911)
#include <iostream>
#include<fstream>
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");
int n, m, viz[30001], cnt ,xx ,yy;
double costt ;
double numar;
typedef struct nod
{
int x;
double cost;
nod *a;
} *pNod;
pNod v[30001];
void add(pNod &dest, int val,double c)
{
pNod p;
p=new nod;
p->x=val;
p->cost=c;
p->a=dest;
dest=p;
}
void citire()
{
f>>n>>m;
int i, x, y;
double c;
f>>xx>>yy;
for (i=1;i<=m;i++)
{
f>>x>>y>>c;
add(v[x],y,c);
add(v[y],x,c);
}
}
void DF(int nod)
{
pNod p;
if (nod==yy)
{
g<<costt;
}
else {
viz[nod] = 1;
for (p=v[nod];p!=NULL;p=p->a)
{
if (!viz[p->x])
if (p->x<nod)
{
costt-=p->cost;
DF(p->x);
// costt+=p->cost;
}
else
{
costt+=p->cost;
DF(p->x);
// costt-=p->cost;
} }
}
}
int main()
{ // int k;
citire();
// int i;
DF(xx);
// printf("%d\n",cnt);
//g<<costt;
}