Cod sursa(job #846721)

Utilizator ericptsStavarache Petru Eric ericpts Data 2 ianuarie 2013 18:04:50
Problema Distante Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <vector>
#include <cstring>
#include <algorithm>
#include <fstream>
using namespace std;

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

#define ushort int

const int maxn = 50005;

int found[maxn];
int main()
{
    int t,n,m,s,i;
    int k;
    int a,b,c;
    bool ok;
    in >> t;
    for( k = 1; k <= t; ++ k)
    {
        in >> n >> m >> s;
        memset(found,0,sizeof(found));
        for(i = 1 ; i <= n ; ++ i)
        {
            in >> found [ i ];
        }
        ok = 1;
        if(found[s] != 0)
        {
            ok = 0;
            continue ;
        }
        for(i = 1 ; i <= m ; ++ i )
        {
            in >> a >> b >> c;
            if(found[a] + c < found[b] || found[b] + c < found[a])
                ok = 0;
        }
        if(ok)
            out << "DA\n";
        else
            out << "NU\n";
    }
    return 0;
}