Pagini recente » Cod sursa (job #2506156) | Cod sursa (job #2295346) | Cod sursa (job #3255001) | Cod sursa (job #2569973) | Cod sursa (job #2635398)
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
ifstream fin ("distante.in");
ofstream fout("distante.out");
#define cin fin
#define cout fout
#define Nmax 50010
#define oo (int)INT_MAX / 2 - 1
int compare[Nmax];
int dist[Nmax];
bitset < Nmax > viz;
vector < pair < int, int > > g[Nmax];
priority_queue < int, vector < int >, greater < int > > pq;
int n, m, k;
void d(int start) {
dist[start] = 0;
pq.push(start);
viz[start] = 1;
while(!pq.empty()) {
int nod = pq.top();
pq.pop();
viz[nod] = 0;
for(auto it : g[nod]) {
int v = it.first;
int c = it.second;
if(dist[nod] + c < dist[v]) {
dist[v] = dist[nod] + c;
if(viz[v] == false) {
pq.push(v);
viz[v] = 1;
}
}
}
}
}
void solve() {
cin >> n >> m >> k;
for(int i=1; i <= n; i++) {
cin >> compare[i];
dist[i] = oo;
}
while(m--) {
int x, y, c;
cin >> x >> y >> c;
g[x].push_back({y, c});
g[y].push_back({x, c});
}
d(k);
for(int i=1; i <= n; i++) {
if(compare[i] != dist[i]) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin .tie(0);
cout.tie(0);
int testCases = 1;
cin >> testCases;
while(testCases--) {
solve();
}
}