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