Cod sursa(job #863363)

Utilizator cernat.catallinFMI Cernat Catalin Stefan cernat.catallin Data 23 ianuarie 2013 19:12:21
Problema Distante Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

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

vector<unsigned int> cost;
int n, m, t, s;
bool bun;

int main(){
    int x, y, c;
    f >> t;
    for(int i = 1; i <= t; ++i){
        bun = true;
        f >> n >> m >> s;
        cost.resize(n+1);
        for(int j = 1; j <= n; ++j) f >> cost[j];

        if(cost[s] != 0){
            g << "NU\n";
            return 0;
        }

        for(int j = 1; j <= m; ++j){
            f >> x >> y >> c;
            if(cost[y] > cost[x] + c) bun = false;
        }

        if(!bun) g << "NU\n";
            else g << "DA\n";
    }
    f.close();
    g.close();

    return 0;
}