Cod sursa(job #1592274)

Utilizator CnemusTudor Luca Ioan Cnemus Data 7 februarie 2016 13:43:27
Problema Sate Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <iostream>
#include <fstream>
#include <list>
using namespace std;

ifstream in("sate.in");
ofstream out("sate.out");

#define LIM 100034

struct edges {
    int nr;
    int length;
};

struct graf {
    list <edges> vertex;
} G[LIM];

int N,M,X,Y,seen[LIM],rue,a,b;

void construct (){
    int d;
    edges e;
    in>>N>>M>>X>>Y;
    while(M){
        M--;
        in>>a>>b>>d;
        e.length=d;
        e.nr=b;
        G[a].vertex.push_back(e);
        e.nr=a;
        G[b].vertex.push_back(e);
    }
}

void parcourant (int x){
    seen[x]=1;
    while(!G[x].vertex.empty()){
        edges y=G[x].vertex.front();
        G[x].vertex.pop_front();
        if(seen[y.nr]==1) continue;
        int aux=rue;
        if(x>y.nr) {
            rue-=y.length;
            //cout<<rue<<endl;
        }
        else {
            rue+=y.length;
           // cout<<rue<<endl;
        }
        if(y.nr==Y) {
            out<<rue;
            break;
        }

        if(seen[y.nr]==0){
            //cout<<y.nr<<"see"<<seen[y.nr]<<endl;
            parcourant(y.nr);
        }
        rue=aux; cout<<x<<'l'<<rue<<endl;;
    }
}




int main()
{
    construct();
    parcourant(X);

    in.close();
    out.close();
    return 0;
}