Nu aveti permisiuni pentru a descarca fisierul grader_test10.in
Cod sursa(job #3227777)
Utilizator | Data | 2 mai 2024 15:32:07 | |
---|---|---|---|
Problema | Distante | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.75 kb |
#include <fstream>
std::ifstream in { "distante.in" };
std::ofstream out { "distante.out" };
int d[50001];
bool read_and_check_graph() {
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() {
int graph_count;
in >> graph_count;
for (int graph = 0; graph < graph_count; graph++)
out << (read_and_check_graph() ? "DA\n" : "NU\n");
}