Submission #511369

# Submission time Handle Problem Language Result Execution time Memory
511369 2022-01-15T17:35:55 Z tabr Crocodile's Underground City (IOI11_crocodile) C++17
100 / 100
679 ms 51996 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        g[r[i][0]].emplace_back(i);
        g[r[i][1]].emplace_back(i);
    }
    vector<vector<int>> c(n);
    vector<int> d(n, (int) 1e9 + 1);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    for (int i = 0; i < k; i++) {
        c[p[i]].emplace_back(0);
        c[p[i]].emplace_back(0);
        d[p[i]] = 0;
        pq.emplace(0, p[i]);
    }
    while (!pq.empty()) {
        auto [e, v] = pq.top();
        pq.pop();
        if (d[v] != e) {
            continue;
        }
        if (v == 0) {
            break;
        }
        for (int id : g[v]) {
            int to = v ^ r[id][0] ^ r[id][1];
            c[to].emplace_back(d[v] + l[id]);
            if (c[to].size() > 1) {
                sort(c[to].begin(), c[to].end());
                if (c[to].size() > 2) {
                    c[to].resize(2);
                }
                if (d[to] > c[to][1]) {
                    d[to] = c[to][1];
                    pq.emplace(d[to], to);
                }
            }
        }
    }
    debug(d);
    return d[0];
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k, r[100][2], l[100], p[100];
    cin >> n >> m >> k;
    for (int i = 0; i < m; i++) {
        cin >> r[i][0] >> r[i][1] >> l[i];
    }
    for (int i = 0; i < k; i++) {
        cin >> p[i];
    }
    debug(travel_plan(n, m, r, l, k, p));
    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 312 KB Output is correct
12 Correct 4 ms 684 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 312 KB Output is correct
12 Correct 4 ms 684 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 679 ms 44332 KB Output is correct
17 Correct 79 ms 17212 KB Output is correct
18 Correct 87 ms 16488 KB Output is correct
19 Correct 580 ms 51996 KB Output is correct
20 Correct 248 ms 36564 KB Output is correct
21 Correct 37 ms 6620 KB Output is correct
22 Correct 323 ms 36816 KB Output is correct