Cod sursa(job #2702780)

Utilizator AlexandruGabrielAliciuc Alexandru AlexandruGabriel Data 5 februarie 2021 20:34:13
Problema Distante Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <bits/stdc++.h>

using namespace std;

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

const int N = 50005;
int T, n, m, S, dist[N];
bool gasit;

int main()
{
    fin >> T;
    while (T--)
    {
        gasit = 1;
        fin >> n >> m >> S;
        for (int i = 1; i <= n; i++)
            fin >> dist[i];
        while (m--)
        {
            int a, b, cost;
            fin >> a >> b >> cost;

            if (dist[a] <= dist[b] && dist[a] + cost < dist[b])
                gasit = 0;
            if (dist[b] < dist[a] && dist[b] + cost < dist[a])
                gasit = 0;

        }
        if (dist[S] != 0)
            gasit = 0;
        if (gasit)
            fout << "DA\n";
        else
            fout << "NU\n";
    }
    return 0;
}