Cod sursa(job #1876942)

Utilizator mihai.alphamihai craciun mihai.alpha Data 12 februarie 2017 19:24:05
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <bits/stdc++.h>

using namespace std;

FILE *fin = fopen("distante.in", "r");
FILE *fout = fopen("distante.out", "w");

#define BUF 1 << 17
char buf[BUF];
int pos = BUF;

inline char next()  {
    if(pos == BUF)
        fread(buf, 1, BUF, fin), pos = 0;
    return buf[pos++];
}

inline int read()  {
    int x = 0;
    char ch = next();
    while(!isdigit(ch))  {
        ch = next();
    }
    while(isdigit(ch))
        x = x * 10 + ch - '0', ch = next();
    return x;
}

#define MAX_N 50001
#define MAX_M 100001

int T, N, M, S;
int D[MAX_N];

int main()  {
    T = read();
    for(int rmq = 1;rmq <= T;rmq++)  {
        N = read(), M = read(), S = read();
        bool ok = 1;
        for(int j = 1;j <= N;j++)  {
            D[j] = read();
        }
        if(D[S] != 0)  {
            ok = 0;
        }
        for(int j = 1;j <= M;j++)  {
            int a, b, c;
            a = read(), b = read(), c = read();
            if(D[a] + c < D[b] || D[b] + c < D[a])  {
                ok = 0;
            }
        }
        if(ok == 1)
            fprintf(fout, "DA\n");
        else
            fprintf(fout, "NU\n");
    }
    fclose(fin);
    fclose(fout);
    return 0;
}