Cod sursa(job #1594296)

Utilizator Darius15Darius Pop Darius15 Data 9 februarie 2016 13:25:24
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>
#include <vector>
#include <bitset>
using namespace std;
ifstream f("distante.in");
ofstream g("distante.out");
int d[50001],z,x,y,c,t,i,n,m,s,j;
int main()
{
    f>>t;
    for (i=1;i<=t;i++){
    vector <pair <int,int > > v[50001];
    bool ok=true;
    int a[50001];
      f>>n>>m>>s;
      for (j=1;j<=n;j++)
        f>>d[j],a[j]=1<<31-1;
        for (j=1;j<=m;j++)
        {
          f>>x>>y>>c;
          v[x].push_back(make_pair(y,c));
          v[y].push_back(make_pair(x,c));
        }
      if (d[s]!=0) g<<"NU"<<'\n';
        else{
           for (j=1;j<=n;j++)
              if (j!=s)
                 for (z=0;z<v[j].size();z++)
                 if (d[j]==d[v[j][z].first]+v[j][z].second && a[j]>d[j])
                 a[j]=d[j];
                 else if (d[j]>d[v[j][z].first]+v[j][z].second)
                  a[j]=d[j]-1;
         for (j=1;j<=n;j++)
          if (j!=s)
             if (d[j]!=a[j]) ok=false;
         if (ok==false) g<<"NU"<<'\n';
         else g<<"DA"<<'\n';
    }
    }
    return 0;
}