Submission #1153170

#TimeUsernameProblemLanguageResultExecution timeMemory
1153170burgerguy사이버랜드 (APIO23_cyberland)C++20
0 / 100
17 ms6724 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int>y, std::vector<int> c, std::vector<int> arr) {
    vector<vector<pair<ll,ll>>> adj(N);
    for (int i = 0; i < M; i++) {
        adj[x[i]].emplace_back(y[i], c[i]);
        adj[y[i]].emplace_back(x[i], c[i]);
    }

    priority_queue<pair<double,ll>, vector<pair<double,ll>>, greater<>> pq;

    pq.emplace(0, 0);

    vector<bool> vis(N);
    vector<double> dist(N, INT_MAX);
    dist[0] = 0;

    while(!pq.empty()) {
        ll curCountry = pq.top().second;
        double curScore = pq.top().first;

        pq.pop();

        if(vis[curCountry]) continue;

        vis[curCountry] = true;

        if(curCountry == H) continue;

        for(pair<ll,ll> u : adj[curCountry]) {
            ll newScore = curScore + u.second;

            if(newScore < dist[u.first]) {
                dist[u.first] = newScore;
                pq.emplace(newScore, u.first);
            }
        }
    }

    double ans = 0;
    if(!vis[H]) ans = -1;
    else ans = dist[H];

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...