Cod sursa(job #2425366)

Utilizator CristyXtremeSimion Cristian CristyXtreme Data 24 mai 2019 19:09:49
Problema Distante Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

vector <vector <pair <int, int> > > v(50001);
vector <int> d(50001);

void check(int n, int m, int s) {
    bool gasit;

    for (int i = 1; i <= n; i++) {
        if (i == s) {
            if (d[i] != 0) {
                out << "NU\n";
                return;
            }
        }
        else {
            gasit = false;

            for (auto muchie : v[i]) {
                if (d[i] > d[muchie.second] + muchie.first) {
                    out << "NU\n";
                    return;
                }
              //  if (d[i] == d[muchie.second] + muchie.first)
                //    gasit = true;
            }
            
            //if (!gasit) {
              //  out << "NU\n";
                //return;
            //}

        }
    }

    out << "DA\n";
}

int main() {
    int t, n, m, s;
    int a, b, c;

    in >> t;
    for (int i = 0; i < t; i++) {
        in >> n >> m >> s;
        
        for (int j = 1; j <= n; j++)
            in >> d[j];
        
        for (int j = 0; j < m; j++) {
            in >> a >> b >> c;
            v[a].push_back({c, b});
            v[b].push_back({c, a});
        }

        check(n, m, s);
        for (int i = 1; i <= n; i++)
            v[i].clear();
    }

    return 0;
}