Pagini recente » Cod sursa (job #2728210) | Cod sursa (job #2743316) | Cod sursa (job #2258015) | Cod sursa (job #3140866) | Cod sursa (job #1070215)
#include <fstream>
#include <vector>
#include <cstring>
using namespace std;
ifstream fin("distante.in");
ofstream fout("distante.out");
const int MAXN = 50005;
int a, b, c, N, M, S, T;
int best[MAXN];
bool marked[MAXN];
string solve() {
int i, k = 1;
bool ok = true;
memset(marked, 0, sizeof(marked));
fin >> N >> M >> S;
marked[S] = true;
for (i = 1; i <= N; ++i)
fin >> best[i];
for (i = 0; i < M; ++i) {
fin >> a >> b >> c;
if (best[a] + c < best[b] || best[b] + c < best[a])
ok = false;
if (!marked[b] && (best[a] + c == best[b])) {
marked[b] = true;
k++;
}
if (!marked[a] && (best[b] + c == best[a])) {
marked[a] = true;
k++;
}
}
if (!ok || best[S] != 0 || k != N)
return "NU";
return "DA";
}
int main() {
fin >> T;
while (T--)
fout << solve() << '\n';
fin.close();
fout.close();
return 0;
}