Submission #717599

# Submission time Handle Problem Language Result Execution time Memory
717599 2023-04-02T09:17:36 Z hafo Crocodile's Underground City (IOI11_crocodile) C++14
0 / 100
5 ms 9684 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}

const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 7;
const ll oo = 1e17 + 69;

int n, m, r[maxn][2], l[maxn], k, p[maxn];
ll f[maxn][2];
int trace[maxn][2];
vector<pa> g[maxn];

int travel_plan(int n, int m, int r[][2], int l[], int k, int p[])
{
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
    memset(f, 0x3f, sizeof f);
    memset(trace, -1, sizeof trace);
    for(int i = 0; i < k; i++) {
        f[p[i]][0] = 0;
        q.push({0, p[i]});
    }

    for(int i = 0; i < m; i++) {
        int u = r[i][0], v = r[i][1];
        g[u].push_back({v, l[i]});
        g[v].push_back({u, l[i]});
    }

    while(!q.empty()) {
        int u = q.top().second;
        long long fu = q.top().first;
        q.pop();

        if(fu > f[u][1]) continue;
        for(auto e:g[u]) {
            int v = e.first, w = e.second;
            if(f[v][0] == 0) continue;
            if(trace[u][0] == v || trace[u][1] == v) continue;
            if(f[v][0] > fu + w) {
                f[v][1] = f[v][0];
                trace[v][1] = trace[v][0];
                f[v][0] = fu + w;
                trace[v][0] = u;
                q.push({fu + w, v});
            } else if(f[v][1] > fu + w) {
                f[v][1] = fu + w;
                trace[v][1] = u;
                q.push({fu + w, v});
            }
        }
    }

    int res = 0, u = 0;
    vector<int> path;
    while(trace[u][1] != -1) {
        path.pb(u);
        u = trace[u][1];
    }
    path.pb(u);
    for(int i = 0; i < (int) path.size() - 1; i++) {
        int u = path[i], v = path[i + 1];
        for(auto e:g[u]) {
            if(e.first == v) res += e.second;
        }
    }
    return res;
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 5 ms 9684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 5 ms 9684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 5 ms 9684 KB Output isn't correct
3 Halted 0 ms 0 KB -