Cod sursa(job #3227775)

Utilizator teodorobertTeodorescu Robert-Andrei teodorobert Data 2 mai 2024 15:25:35
Problema Distante Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>

static int d[50001];

bool read_and_check_graph(std::istream& in) {
    int nodes;
    int edges;
    int source;
    in >> nodes >> edges >> source;

    for (int node = 1; node <= nodes; node++)
        in >> d[node];

    for (int edge = 1; edge <= edges; edge++) {
        int node1;
        int node2;
        int cost;
        in >> node1 >> node2 >> cost;

        if (d[node1] + cost < d[node2] || d[node2] + cost < d[node1])
            return false;
    }

    if (d[source])
        return false;
    return true;
}

int main() {
    std::ifstream in { "distante.in" };
    std::ofstream out { "distante.out" };

    int graph_count;
    in >> graph_count;

    for (int graph = 0; graph < graph_count; graph++)
        out << (read_and_check_graph(in) ? "DA\n" : "NU\n");
}