Cod sursa(job #1222634)

Utilizator rangerChihai Mihai ranger Data 23 august 2014 21:58:59
Problema Distante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include<fstream>
#include<vector>
using namespace std;

ifstream cin("distante.in");
ofstream cout("distante.out");
const int nmax = 50010;
int t,n,m,s,i;
int d[nmax];
vector<pair<int, int > > g[nmax];

int main()
{
    cin>>t;
    while (t--)
    {
        cin>>n>>m>>s;
        int ok=1;
        for (i=1;i<=n;i++) cin>>d[i];
        for (i=1;i<=m;i++) {
            int x,y,z;
            cin>>x>>y>>z;
            g[x].push_back(make_pair(y,z));
            g[y].push_back(make_pair(x,z));
        }
        if (d[s]!=0) ok=0;
        for (i=1;i<=n && ok;i++) if (i!=s)
        {
            int gasit=0;
            for (int j=0;j<g[i].size();++j) {
                int to=g[i][j].first,len=g[i][j].second;
                if (d[to]+len==d[i]) gasit=1;
                if (d[to]+len<d[i]) ok=0;
            }
            if (gasit==0) ok=0;
        }
        if (ok==1) cout<<"DA\n"; else cout<<"NU\n";
    }
    return 0;
}