Cod sursa(job #888581)

Utilizator StanAndreiAndrei Stan StanAndrei Data 24 februarie 2013 11:43:04
Problema Ubuntzei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <string.h>

using namespace std;

ifstream f1("ubuntzei.in");
ofstream f2("ubuntzei.out");

#define NMAX 2005

int N,SOL[NMAX],a[NMAX][NMAX],K=1,M;

long long int nivmax=0;

bool viz[NMAX];

char S[NMAX];

void cit()
{
    int i,j,x,y,c;

    f1>>N>>M;

   f1.get();
   f1.getline(S,NMAX);
   int len=strlen(S);
    for (i=0;i<len;i+=2)
       SOL[K++]=S[i]-'0';
    f1.get();
    for (i=1;i<=M;i++)
    {
        f1>>x>>y>>c;
        a[x][y]=c;
        a[y][x]=c;
    }
    K--;
}

void dfs(int p,int nivel)
{
    if (nivel>nivmax)
        nivmax=nivel;
    viz[p]=1;
    int i;

    for (i=1;i<=N;i++)
        if(!viz[i] && a[p][i]!=0)
            dfs(i,nivel+a[p][i]);
}

int main()
{
    cit();
    dfs(1,0);
    f2<<nivmax;

    f1.close();
    f2.close();
    return 0;
}