Pagini recente » Cod sursa (job #2528391) | Monitorul de evaluare | Cod sursa (job #1214442) | Cod sursa (job #2918717) | Cod sursa (job #3351021)
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int main() {
freopen("distante.in", "r", stdin);
freopen("distante.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int N, M, S;
cin >> N >> M >> S;
vector<long long> D(N + 1);
for (int i = 1; i <= N; i++) {
cin >> D[i];
}
vector<int> okPred(N + 1, 0);
bool good = true;
if (D[S] != 0) {
good = false;
}
for (int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
if (D[a] + c < D[b]) {
good = false;
}
if (D[b] + c < D[a]) {
good = false;
}
if (D[a] + c == D[b]) {
okPred[b] = 1;
}
if (D[b] + c == D[a]) {
okPred[a] = 1;
}
}
for (int i = 1; i <= N; i++) {
if (i == S) {
continue;
}
if (!okPred[i]) {
good = false;
}
}
if (good) {
cout << "DA\n";
}
else {
cout << "NU\n";
}
}
return 0;
}