Pagini recente » Cod sursa (job #2574384) | Cod sursa (job #1487025) | Cod sursa (job #1224972) | Cod sursa (job #735020) | Cod sursa (job #183837)
Cod sursa(job #183837)
#include<stdio.h>
#define in "sate.in"
#define out "sate.out"
struct nod{
int inf,dist;
nod *next;
} *l[30001];
long n,X,Y,m,suma;
int s[30001];
void add(int,int,int);
void df(int);
int main()
{
freopen(in,"r",stdin);
freopen(out,"w",stdout);
int i,x,y,z;
scanf("%d%d%d%d",&n,&m,&X,&Y);
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&z);
add(x,y,z);
}
df(X);
printf("%d",suma);
return 0;
}
void add(int x,int y,int z)
{
nod *p=new nod;
p->inf=x;
p->dist=z;
p->next=l[y];
l[y]=p;
p=new nod;
p->inf=y;
p->dist=z;
p->next=l[x];
l[x]=p;
}
void df(int nodc)
{
if(nodc==Y)
return;
s[nodc]=1;
nod *p=l[nodc];
while(p)
{
if(!s[p->inf])
{
if(nodc>p->inf)
suma-=p->dist;
else
suma+=p->dist;
df(p->inf);
}
p=p->next;
}
}