Submission #770835

# Submission time Handle Problem Language Result Execution time Memory
770835 2023-07-02T03:37:46 Z jlallas384 Crocodile's Underground City (IOI11_crocodile) C++17
0 / 100
2 ms 352 KB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
using ll = long long;
int travel_plan(int n, int m, int r[][2], int L[], int k, int p[]){
    vector<vector<pair<int,int>>> g(n);
    for(int i = 0; i < m; i++){
        g[r[i][0]].emplace_back(r[i][1], L[i]);
        g[r[i][1]].emplace_back(r[i][0], L[i]);
    }
    vector<int> ext(n);
    for(int i = 0; i < k; i++){
        ext[p[i]] = 1;
    }
    vector<ll> dist(n, 1e18);
    vector<int> par(n), dep(n);
    priority_queue<pair<ll,int>> pq;
    pq.emplace(0, 0);
    dist[0] = 0;
    vector<vector<pair<int,int>>> dag(n);
    while(pq.size()){
        auto [d,v] = pq.top(); pq.pop();
        if(ext[v]) continue;
        if(-d > dist[v]) continue;
        for(auto [u,w]: g[v]){
            if(dist[v] + w < dist[u]){
                dist[u] = dist[v] + w;
                pq.emplace(-dist[u], u);
                par[u] = v;
            }
            if(par[v] != u) dag[v].emplace_back(u, w);
        }
    }
    vector<ll> dp(n, -1);
    vector<int> here;
    function<ll(int)> dfs = [&](int v){
        if(dp[v] != -1) return dp[v];
        if(ext[v]) return dp[v] = 0;
        here[v] = 1;
        vector<ll> dists;
        for(auto [u,w]: dag[v]){
            if(here[u]) assert(false);
            dists.push_back(dfs(u) + w);
        }
        here[v] = 0;
        if(dists.size() < 2) return dp[v] = (ll) 1e10;
        sort(dists.begin(), dists.end());
        return dp[v] = dists[1];
    };
    return (int) dfs(0);
}



# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 352 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 352 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 352 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -