Cod sursa(job #2702210)

Utilizator DragosSDragos Sarbu DragosS Data 3 februarie 2021 10:36:49
Problema Distante Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <bits/stdc++.h>
#define nmax 100003
#define oo 2000000004
using namespace std;

struct muchie
{
    int x, y, cost;
};

ifstream fin("distante.in");
ofstream fout("distante.out");
muchie a[100005];
int n, m, S, d[50003], T;

int main()
{
    int i, x, y, c, corect;
    fin >> T;
    while (T--)
    {
        fin >> n >> m >> S;
        for (i = 1; i <= n; i++)
            fin >> d[i];
        for (i = 1; i <= m; i++)
            fin >> a[i].x >> a[i].y >> a[i].cost;
        corect = 1;
        if(d[s] != 0) corect=0;
        for (i = 1; i <= m && corect; i++)
        {
            x = a[i].x;
            y = a[i].y;
            c = a[i].cost;
            if (d[x] <= d[y] && d[x] + c < d[y]) corect = 0;
            if (d[y] < d[x] && d[y] + c < d[x]) corect = 0;
        }
        if (corect) fout << "DA\n";
        else fout << "NU\n";
    }
    fout.close();
    fin.close();
    return 0;
}