Cod sursa(job #1356502)

Utilizator killlerr1Chilom Mircea killlerr1 Data 23 februarie 2015 14:18:35
Problema Distante Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <vector>
using namespace std;

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

struct Edge{
    int nod, cost;
};

int n, m, s, t;
int dmin[50001];
int a, b, c;
bool ok;

int main()
{
    is >> t;
    string str;
    while(t)
    {
        vector<vector<Edge> > G;
        ok = true;
        is >> n >> m >> s;
        G.resize(n+1);
        for( int i = 1; i <= n; ++i )
            is >> dmin[i];
        for( int i = 1; i <= m; ++i )
        {
            is >> a >> b >> c;
            G[a].push_back({b, c});
            G[b].push_back({a, c});
        }
        for( a = 1; a <= n; ++a )
            for( const auto& e : G[a] )
                if( dmin[a] + e.cost < dmin[e.nod] || dmin[e.nod] + e.cost < dmin[a] )
                    ok = false;
        if( ok == false )
            str = "NU";
        else
            str = "DA";
        os << str << '\n';
        --t;
    }

    is.close();
    os.close();
}