Cod sursa(job #3239810)

Utilizator Mihai_OctMihai Octavian Mihai_Oct Data 7 august 2024 17:54:56
Problema Distante Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("distante.in");
ofstream fout("distante.out");
int n, m, i, j, x, y, c, o, t, s;
int dist[50002];
bool ok;

static inline void Calc() {
    fin >> n >> m >> s;
    ok = true;

    for(i = 1; i <= n; i++) fin >> dist[i];
    for(i = 1; i <= m; i++) {
        fin >> x >> y >> c;
        if(dist[x] + c < dist[y] || dist[y] + c < dist[x]) ok = false;
    }
    if(dist[s]) ok = false;

    if(ok) fout << "DA\n";
    else fout << "NU\n";
}

int main() {
    fin >> t;
    while(t--) Calc();

    return 0;
}