Pagini recente » Cod sursa (job #818062) | Cod sursa (job #1924805) | Cod sursa (job #3147803) | Cod sursa (job #1852814) | Cod sursa (job #590691)
Cod sursa(job #590691)
#include<fstream>
#include<vector>
#define inf 0x3f3f
using namespace std;
vector<vector<long> >mat(50001);
vector<vector<long> >cost(50001);
vector<long long> dist(50001,inf),dist1(50001);
#include<queue>
queue<long> q;
long long n,m,x,y,c,t,s;
int main()
{
ifstream f("distante.in");
ofstream g("distante.out");
f>>t;
long xx,i,j,ok=0;
while(t)
{
ok=0;
f>>n>>m>>s;
for(i=1;i<=n;++i)
{
dist[i]=inf;
mat[i].clear();
cost[i].clear();
}
for(i=1;i<=n;++i)
f>>dist1[i];
for(;m;--m)
{
f>>x>>y>>c;
mat[x].push_back(y);
mat[y].push_back(x);
cost[x].push_back(c);
cost[y].push_back(c);
}
q.push(s);
dist[s]=0;
while(!q.empty())
{
xx=q.front();
for(i=0;i<mat[xx].size();++i)
if(dist[xx]+cost[xx][i]<dist[mat[xx][i]])
{
q.push(mat[xx][i]);
dist[mat[xx][i]]=dist[xx]+cost[xx][i];
}
q.pop();
}
for(i=1;i<=n;++i)
if(dist[i]!=dist1[i])
{
ok=1;
break;
}
if(!ok)
g<<"DA\n";
else
g<<"NU\n";
--t;
}
}