Cod sursa(job #363365)

Utilizator popoiu.georgeGeorge Popoiu popoiu.george Data 12 noiembrie 2009 21:19:42
Problema Sate Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include<fstream>
#include<iostream>
#define inf "sate.in"
#define outf "sate.out"
#define MaxN 30001
#define MaxM 100026
using namespace std;

fstream f(inf,ios::in),g(outf,ios::out);

int LA[3][MaxM];
int Start[MaxN];
int s[MaxN];
int Coada[MaxN],i_c=1,s_c=1;
long long Cost[MaxN];
int N,M,X,Y;

struct muchie
{
int nod1;
int nod2;
long long cost;
};

muchie MC[MaxM];

void Citire()
{
f>>N>>M>>X>>Y;
int i,j,d,k=0;
while(f>>i>>j>>d)
    {
    k++;
    LA[1][k]=j;
    LA[2][k]=d;
    LA[0][k]=Start[i];
    Start[i]=k;
    k++;
    LA[1][k]=i;
    LA[2][k]=d;
    LA[0][k]=Start[j];
    Start[j]=k;
    }
}

void BFS(int nod)
{
int aux;
s[nod]=1;
Coada[i_c]=nod;
while(i_c<=s_c)
    {
    aux=Start[Coada[i_c]];
    while(aux)
        {
        if(s[LA[1][aux]]==0)
            {
            s[LA[1][aux]]=1;
            s_c++;
            Coada[s_c]=LA[1][aux];
            Cost[LA[1][aux]]=Cost[Coada[i_c]]+LA[2][aux];
            }
        aux=LA[0][aux];
        }
    i_c++;
    }
}

int main()
{
Citire();
BFS(X);
g<<Cost[Y];
f.close();
g.close();
return 0;
}