Submission #649397

#TimeUsernameProblemLanguageResultExecution timeMemory
649397mychecksedadCrocodile's Underground City (IOI11_crocodile)C++17
100 / 100
560 ms114628 KiB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
const int X = 1e6, MOD = 1e9+7;



int n, m;
vector<ll> dp[2];
vector<pair<int, ll>> g[X];
bitset<X> is, vis;

void bfs(int v){
    priority_queue<pair<ll, int>> q;
    for(int i = 0; i < n; ++i) if(is[i]) q.push({0, i}), dp[0][i] = dp[1][i] = 0;
    while(!q.empty()){
        int v = q.top().second; q.pop();
        if(vis[v]) continue;
        vis[v] = 1;
        for(auto k: g[v]){
            int u = k.first, e = k.second;
            if(vis[u]) continue;
            ll d = e + dp[1][v];
            if(dp[0][u] > d){
                dp[1][u] = dp[0][u];
                dp[0][u] = d;
                q.push({-dp[1][u], u});
            }else if(dp[1][u] > d){
                dp[1][u] = d;
                q.push({-dp[1][u], u});
            }
        }
    }
}

int travel_plan(int F, int M, int R[][2], int L[], int K, int P[]){ 
    n = F;
    m = M;
    dp[0].resize(n, MOD);
    dp[1].resize(n, MOD);
    for(int i = 0; i < K; ++i) is[P[i]] = 1;
    for(int i = 0; i < m; ++i){
        g[R[i][0]].pb({R[i][1], L[i]});
        g[R[i][1]].pb({R[i][0], L[i]});
    }
    bfs(0);

    return dp[1][0];
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...