Cod sursa(job #1400289)

Utilizator BKmarianmarian BKmarian Data 25 martie 2015 10:51:22
Problema Sate Scor 0
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 1.03 kb
#include <iostream>
#include<fstream>
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");
int n, m, viz[30001], cnt ,xx ,yy ;
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 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+p->cost;
DFS(p->x);
numar=numar-p->cost;}
    else 
{numar=numar-p->cost;
        DFS(p->x);
 numar=numar+p->cost;
} 
   }
       }
}
}
int main()
{   // int k;
    citire();
  //  int i;
    DFS(xx);
  //  printf("%d\n",cnt);
    g<<numar;
}