Submission #669169

# Submission time Handle Problem Language Result Execution time Memory
669169 2022-12-05T22:35:02 Z ljuba Crocodile's Underground City (IOI11_crocodile) C++17
100 / 100
428 ms 52736 KB
#include "crocodile.h"
#include <bits/stdc++.h>

using namespace std;

int travel_plan(int n, int m, int R[][2], int L[], int K, int P[]) {
    vector<bool> vis(n, false);

    vector<vector<pair<int, int>>> adj(n);

    for(int i = 0; i < m; ++i) {
        adj[R[i][0]].push_back({R[i][1], L[i]});
        adj[R[i][1]].push_back({R[i][0], L[i]});
    }

    vector<int> cnt(n);

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;

    for(int i = 0; i < K; ++i) {
        int x = P[i];
        vis[x] = true;

        for(auto e : adj[x]) {
            pq.push({e.second, e.first});
        }
    }

    while(!pq.empty()) {
        auto tren = pq.top();
        pq.pop();

        if(vis[tren.second]) continue;

        ++cnt[tren.second];

        if(cnt[tren.second] == 2) {
            if(tren.second == 0) {
                return tren.first;
            }

            vis[tren.second] = true;

            for(auto e : adj[tren.second]) {
                if(vis[e.first]) continue;
                pq.push({tren.first + e.second, e.first});
            }
        }
    }

    return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 398 ms 48996 KB Output is correct
17 Correct 70 ms 12620 KB Output is correct
18 Correct 83 ms 14060 KB Output is correct
19 Correct 428 ms 52736 KB Output is correct
20 Correct 243 ms 36224 KB Output is correct
21 Correct 41 ms 5884 KB Output is correct
22 Correct 356 ms 32516 KB Output is correct