Cod sursa(job #1589195)

Utilizator metrix007Lungu Ioan Adrian metrix007 Data 3 februarie 2016 20:45:21
Problema Distante Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#define INF 99999999
#define NMAX 50002
using namespace std;

struct punct
{
    int nod,cost;
}p,v;


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




int n,m,x,y,s,c,t,ds[NMAX];

bool dijkstra()
{

    if(ds[s]!=0) return false;

    for(int i=1;i<=m;i++)
        {
            in >> x >> y >> c;
            if(ds[y]>ds[x]+c || ds[x]>ds[y]+c)
                return false;
        }
        return true;
}

int main()
{
    in >> t;

    for(int k=0;k<t;k++)
    {
        in >> n >> m >> s;
        for(int i=1;i<=n;i++)
        {
            in >> ds[i];
        }


        if(dijkstra())
            out << "DA" << "\n";
        else
            out << "NU" << "\n";

    }

    return 0;
}