Pagini recente » Cod sursa (job #602729) | Cod sursa (job #2151276) | Cod sursa (job #2685906) | Cod sursa (job #1128589) | Cod sursa (job #2091146)
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#define f first
#define s second
using namespace std;
ifstream F("distante.in");
ofstream G("distante.out");
int t, n, m, S, x, y, c, ok, v[50005], d[50005];
const int inf = 1 << 30;
bitset<50005> w;
priority_queue<pair<int, int> > pq;
vector<pair<int, int> > a[50005];
int main()
{
ios::sync_with_stdio(false);
F.tie(0);
F >> t;
vector<pair<int, int> > :: iterator it;
while( t-- )
{
w = 0;
F >> n >> m >> S;
for( int i = 1; i <= n; ++ i ) F >> v[ i ], d[ i ] = inf;
for( int i = 0; i < m; ++ i )
{
F >> x >> y >> c;
a[x].push_back({y,c});
a[y].push_back({x,c});
}
d[S] = 0;
pq.push({0, S});
while(!pq.empty())
{
x = pq.top().s;
pq.pop();
if(w[x]) continue;
w[x] = 1;
for(it = a[x].begin(); it != a[x].end(); it++)
if(d[ (*it).f ] > (*it).s + d[x])
d[ (*it).f ] = (*it).s + d[x], pq.push({-d[(*it).f], (*it).f});
}
ok = 1;
for( int i = 1; i <= n && ok; ++ i )
if( v[ i ] != d[ i ] )
{
G << "NU\n";
ok = 0;
}
if( ok ) G << "DA\n";
}
return 0;
}