Cod sursa(job #2618668)

Utilizator drknss_Hehe hehe drknss_ Data 25 mai 2020 18:18:44
Problema Distante Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.13 kb
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long
//#define in cin
//#define out cout


const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 5e4 + 11;
const int NMAX = 1e4 + 11;
const ll INF64 = 3e18 + 1;
const double lil = 0.0000000000001;

ifstream in("distante.in");
ofstream out("distante.out");

int n, m, S;

vector<int>dist, r;
vector<vector<pi>>v;



void Dijkstra(int nod){

    priority_queue<pi, vector<pi>, greater<pi>>unmarked;

    unmarked.push({0,nod});
    dist[nod] = 0;

    while(!unmarked.empty()){

        int cur = unmarked.top().ss;
        int curDist = unmarked.top().ff;

        unmarked.pop();

        if(curDist != dist[cur])continue;

        for(auto it : v[cur]){

            int x = it.ff;
            int weight = it.ss;

            if(dist[cur] + weight < dist[x]){
                dist[x] = dist[cur] + weight;
                unmarked.push({dist[x],x});
            }
        }
    }
}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();

    v.resize(N);
    dist.resize(N, INF64);
    r.resize(N);

    int t = 1;

    in >> t;

    while(t--){

        in >> n >> m >> S;

        for(int i = 0; i <= n; i++){
            dist[i] = INF64;
            v[i].clear();
        }

        for(int i = 1; i <= n; i++)in >> r[i];


        for(int i = 1, x, y, w; i <= m; i++){
            in >> x >> y >> w;
            v[x].push_back({y,w});
            v[y].push_back({x,w});
        }

        Dijkstra(S);

        string ans = "DA";
        for(int i = 1; i <= n; i++){
            //cout << dist[i] << ' ';
            if(r[i] != dist[i]){
                ans = "NU";
                break;
            }
        }//cout << '\n';

        out << ans << '\n';
    }





}