Cod sursa(job #1027969)

Utilizator mihaiSimuSimu Mihai mihaiSimu Data 13 noiembrie 2013 12:30:51
Problema Distante Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <vector>
#include <queue>
#include <bitset>
#define INF 500000000
#define MAXN 50005
using namespace std;

int main(){
    int n,m,t,s,x,y,c;
    vector<int> dTest;
    
    
    freopen("distante.in","r",stdin);
    freopen("distante.out","w",stdout);
    
    cin>>t;
    while(t--){
        cin>>n>>m>>s;
        dTest.resize(n+1);
        for(int i=1;i<=n;i++) {
            cin>>dTest[i];
        }
        bool ok = true;
        bitset<MAXN> okRang;
        okRang.reset();
        
        for(int i=0;i<m;i++) {
            cin>>x>>y>>c;
            if(dTest[x]+c<dTest[y])
                ok = false;
            if(dTest[y]+c<dTest[x])
                ok=false;
            if(dTest[x]+c==dTest[y])
                okRang[y] = true;
            if(dTest[y]+c==dTest[x])
                okRang[x] = true;
        }
        okRang[s] = (dTest[s] == 0);
        
        for(int i=1;i<=n;i++)
            if(!okRang[i])
                ok = false;
        
        if(ok) cout<<"DA\n";
        else cout<<"NU\n";
    }
    
    return 0;
}