Cod sursa(job #1589232)

Utilizator metrix007Lungu Ioan Adrian metrix007 Data 3 februarie 2016 21:04:36
Problema Distante Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#define INF 1 << 29
#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,cost,t,d[NMAX];
bool verf[NMAX];

bool dijkstra()
{
    bool gasit = false;
    if(d[s]!=0) return false;

    for(int i=1;i<=m;i++)
        {
            in >> x >> y >> cost;
            if(d[x]+ cost < d[y])
                return false;
            if(d[x]+cost == d[y]) gasit = true;
        }
    if(gasit) return true;
    return false;
}

int main()
{
    in >> t;

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


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

    }

    return 0;
}