Cod sursa(job #982087)

Utilizator t.g.g.tt.g.g.t t.g.g.t Data 8 august 2013 14:27:21
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <fstream>

using namespace std;

int s,t,n,m,a,b,c,costm[50005],prob,probg,gasit[50005];

int main ()
{

    ifstream in("distante.in");
    ofstream out("distante.out");
    in>>t;
    for (int i=1;i<=t;++i)
    {
        in>>n>>m>>s;
        for (int j=1;j<=n;++j) in>>costm[j];
        probg=1; if (costm[s]==0) gasit[s]=1; else probg=0;
        for (int j=1;j<=m;++j)
        {
            in>>a>>b>>c;
            int folos=0;
            if (gasit[a]==0) if ((costm[a]-c)>costm[b]) probg=0; else if ((costm[a]-c)==costm[b]) { gasit[a]=1; folos=1;}
            if (folos==0) if ((costm[b]-c)>costm[a]) probg=0; else if ((costm[b]-c)==costm[a]) gasit[b]=1;
        }
        for (int j=1;j<=n;++j)
        {
            if (gasit[j]==0) probg=0;
            gasit[j]=0;
        }
        if (probg==1) out<<"DA"<<"\n"; else out<<"NU"<<"\n";
    }
    in.close();
    out.close();

}