Pagini recente » Cod sursa (job #275374) | Cod sursa (job #1627484) | Cod sursa (job #1544799) | Cod sursa (job #1073266) | Cod sursa (job #2392418)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
# define verf ++poz == hg ? f.read (ch, hg), poz = 0 : 0
ifstream f("distante.in");
ofstream g("distante.out");
const int hg = 1 << 13;
int poz;
char ch[hg];
inline void cit ( int &x ) {
if (ch[0] == '\0') f.read (ch, hg) ;
else for (; ch[poz] < '0' || ch[poz] > '9' ; verf) ;
for (x = 0 ; ch[poz] >= '0' && ch[poz] <= '9' ; x = x * 10 + ch[poz] - '0', verf) ;
}
int t,d[50005],n,m,s;
vector < pair<int,int> > a[50005];
string check()
{
int i,j;
bool sw;
for(i=1;i<=n;i++)
{
if(i==s)
{
sw=1;
}
else
{
sw=0;
}
for(j=0;j<a[i].size();j++)
{
if(d[a[i][j].first]>d[i]+a[i][j].second)
{
return "NU\n";
}
if(i!=s)
{
if(d[i]==d[a[i][j].first]+a[i][j].second)
{
sw=1;
}
}
}
if(sw==0)
{
return "NU\n";
}
}
return "DA\n";
}
int main()
{
int i,j,x,y,cost;
cit(t);
while(t--)
{
cit(n);
cit(m);
cit(s);
for(i=1;i<=n;i++)
{
cit(d[i]);
}
while(m--)
{
cit(x);
cit(y);
cit(cost);
a[x].push_back({y,cost});
a[y].push_back({x,cost});
}
g<<check();
for(i=1;i<=n;i++)
{
a[i].clear();
}
}
return 0;
}