Submission #995993

# Submission time Handle Problem Language Result Execution time Memory
995993 2024-06-10T06:45:11 Z 54skyxenon Crocodile's Underground City (IOI11_crocodile) C++17
Compilation error
0 ms 0 KB
// https://oj.uz/problem/view/IOI11_crocodile

/** Needed for linking!!! */
#include "crocodile.h"

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define INF (ll)1e18

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    vector<map<int, int>> graph(N);
    vector<set<int>> visited(N);

    for (int i = 0; i < M; i++) {
        int u = R[i][0];
        int v = R[i][1];
        graph[u][v] = graph[v][u] = L[i];
    }

    // Run Dijkstra's and only care about the second best distance, propagated downwards
    vector<vector<ll>> dist(graph.size(), {INF, INF});
    priority_queue<pair<ll, ll>> pq;

    for (int& p : P) {
        pq.push({0, p});
        dist[p][0] = dist[p][1] = 0;
    }

    while (pq.size()) {
        auto [d, u] = pq.top();
        pq.pop();
        d = -d;

        if (d > dist[u][1]) {
            continue;
        }

        // Thank you to sreepranad Devarakonda from USACO Guide
        for (auto& [v, w] : graph[u]) {
            ll cost = w + d;

            if (cost < dist[v][0]) {
                if (dist[v][0] != dist[v][1] && dist[v][0] < INF) {
                    dist[v][1] = dist[v][0];
                    pq.push({-dist[v][1], v});
                }
                dist[v][0] = cost;
            }
            else if (cost < dist[v][1]) {
                dist[v][1] = cost;
                pq.push({-cost, v});
            }
        }
    }

    return dist[0][1];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:26:19: error: 'begin' was not declared in this scope
   26 |     for (int& p : P) {
      |                   ^
crocodile.cpp:26:19: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from crocodile.cpp:6:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from crocodile.cpp:6:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
crocodile.cpp:26:19: error: 'end' was not declared in this scope
   26 |     for (int& p : P) {
      |                   ^
crocodile.cpp:26:19: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from crocodile.cpp:6:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from crocodile.cpp:6:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~