Submission #1018145

# Submission time Handle Problem Language Result Execution time Memory
1018145 2024-07-09T15:20:11 Z stdfloat Crocodile's Underground City (IOI11_crocodile) C++17
89 / 100
315 ms 63988 KB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;

#define ff  first
#define ss  second
#define pii pair<int, int>

using ll = long long;

int travel_plan(int n, int M, int R[][2], int L[], int K, int P[]) {
    vector<vector<pii>> E(n);
    for (int i = 0; i < M; i++) {
        E[R[i][0]].push_back({R[i][1], L[i]});
        E[R[i][1]].push_back({R[i][0], L[i]});
    }

    vector<bool> vis(n);
    vector<pair<ll, ll>> dis(n, {LLONG_MAX, LLONG_MAX});
    priority_queue<pair<ll, int>> q;
    for (int i = 0; i < K; i++) {
        vis[P[i]] = true;
        dis[P[i]] = {0, 0};
        q.push({0, P[i]});
    }

    while (!q.empty()) {
        auto [d, x] = q.top(); d = -d; q.pop();
    
        if (d != dis[x].ff) continue;

        if (!vis[x]) {
            vis[x] = true;

            dis[x].ff = dis[x].ss;
            dis[x].ss = LLONG_MAX;         
            continue;
        }

        for (auto [i, w] : E[x]) {
            if (d + w < dis[i].ss && (!vis[i] || d + w < dis[i].ff)) {
                dis[i].ss = d + w;

                if (dis[i].ff > dis[i].ss) swap(dis[i].ff, dis[i].ss);

                q.push({-d - w, i});
            }
        }
    }

    return (dis[0].ff == LLONG_MAX ? -1 : dis[0].ff);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 412 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 412 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 488 KB Output is correct
16 Correct 306 ms 59372 KB Output is correct
17 Correct 46 ms 14600 KB Output is correct
18 Correct 59 ms 16108 KB Output is correct
19 Correct 315 ms 63988 KB Output is correct
20 Correct 167 ms 47476 KB Output is correct
21 Correct 25 ms 6236 KB Output is correct
22 Incorrect 188 ms 44608 KB Output isn't correct
23 Halted 0 ms 0 KB -