Cod sursa(job #996462)

Utilizator horatiu11Ilie Ovidiu Horatiu horatiu11 Data 11 septembrie 2013 23:11:13
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;

#define N_MAX 50002

///////////// MAIN /////////////
int main() {
    ifstream fin("distante.in");
    ofstream fout("distante.out");

    int best[N_MAX];
    int x, y, c, i, n, m, s, T;

    // Read
    fin >> T;


    // Compute
    while(T--) {
        fin >> n >> m >> s;
        for(i = 1; i <= n; i++)
            fin >> best[i];

        bool flag = true;
        for(i = 1; i <= m; i++) {
            fin >> x >> y >> c;
            if((best[x] + c < best[y]) || (best[y] + c < best[x]))
                flag = false;
        }
        if(best[s])
            flag = false;


        // Print
        if(flag == true)
            fout << "DA\n";
        else fout << "NU\n";
    }
}