Submission #399263

# Submission time Handle Problem Language Result Execution time Memory
399263 2021-05-05T13:42:19 Z fvogel499 Crocodile's Underground City (IOI11_crocodile) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define pii pair<int, int>
#define MAX_N 50000
#define MAX_M 10000000
#define inf 1e18
#define ll long long

ll dist [MAX_N];
ll secondDist [MAX_N];
bool proc [MAX_N];

struct Compare {
    bool operator()(int a, int b) {
        return (secondDist[a] > secondDist[b]);
    }
};

int travel_plan(int nbNodes, int nbEdges, int corridors [MAX_M][2], int travelTime [MAX_M], int nbExits, int exits [MAX_N]) {
    vector<vector<pii>> graph(nbNodes);
    for (int i = 0; i < nbEdges; i++) {
        graph[corridors[i][0]].push_back(pii(corridors[i][1], travelTime[i]));
        graph[corridors[i][1]].push_back(pii(corridors[i][0], travelTime[i]));
    }

    for (int i = 0; i < nbNodes; i++) {
        dist[i] = inf;
        secondDist[i] = inf;
        proc[i] = false;
    }
    priority_queue<int, vector<int>, Compare> q;
    for (int i = 0; i < nbExits; i++) {
        q.push(exits[i]);
        dist[exits[i]] = 0;
        secondDist[exits[i]] = 0;
    }
    while (!q.empty()) {
        int curNode = q.top();
        q.pop();
        if (proc[curNode]) continue;
        proc[curNode] = true;
        for (pii newEdge : graph[curNode]) {
            int newNode = newEdge.first;
            ll newWeight = newEdge.second;
            ll newDist = secondDist[curNode]+newWeight;
            if (proc[newNode] or newDist > secondDist[newNode]) continue;
            if (newDist <= dist[newNode]) {
                secondDist[newNode] = dist[newNode];
                dist[newNode] = newDist;
            }
            else if (newDist <= secondDist[newNode]) {
                secondDist[newNode] = newDist;
            }
            else {
                cerr << "ISSUE-1";
            }
            q.push(newNode);
        }
    }

    int maxDist = 0;
    for (int i = 0; i < nbNodes; i++) {
        maxDist = max(maxDist, secondDist[i]);
    }

    return maxDist;
}

// int32_t main() {
//     int nbNodes, nbEdges;
//     cin >> nbNodes >> nbEdges; // simul
//     vector<vector<int>> corridors(nbEdges, vector<int>(2));
//     for (int i = 0; i < nbEdges; i++) cin >> corridors[i][0] >> corridors[i][1]; // simul
//     vector<int> travelTime(nbEdges);
//     for (int i = 0; i < nbEdges; i++) cin >> travelTime[i]; // simul
//     int nbExits;
//     cin >> nbExits;
//     vector<int> exits(nbExits);
//     for (int i = 0; i < nbExits; i++) cin >> exits[i];
//     cout << travel_plan(nbNodes, nbEdges, corridors, travelTime, nbExits, exits);
// }

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:68:45: error: no matching function for call to 'max(int&, long long int&)'
   68 |         maxDist = max(maxDist, secondDist[i]);
      |                                             ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from crocodile.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
crocodile.cpp:68:45: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   68 |         maxDist = max(maxDist, secondDist[i]);
      |                                             ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from crocodile.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
crocodile.cpp:68:45: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   68 |         maxDist = max(maxDist, secondDist[i]);
      |                                             ^
In file included from /usr/include/c++/9/algorithm:62,
                 from crocodile.cpp:4:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
crocodile.cpp:68:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   68 |         maxDist = max(maxDist, secondDist[i]);
      |                                             ^
In file included from /usr/include/c++/9/algorithm:62,
                 from crocodile.cpp:4:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
crocodile.cpp:68:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   68 |         maxDist = max(maxDist, secondDist[i]);
      |                                             ^