Submission #979640

# Submission time Handle Problem Language Result Execution time Memory
979640 2024-05-11T09:17:15 Z vjudge1 Swapping Cities (APIO20_swap) C++17
Compilation error
0 ms 0 KB
#include "swap.h"

#include <cassert>
#include <cstdio>

#include <string>

#include <vector>
#include <map>
#include <set>

using namespace std;
vector<pair<int, int>> g[200005];
pair<int, int> p[200005];
map<pair<int, int>, int> mp, pos;
set<pair<int, int>> st;
int x, y, mx;
void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
      x = N;
      y = M;
      for(int i = 0; i < M; i++){
          int a = U[i] + 1, b = V[i] + 1, c = W[i];
          g[a].push_back({b, c});
          g[b].push_back({a, c});
          mp[{a, b}] = c;
          mp[{b, a}] = c;

          pos[{a, b}] = i + 1;
          pos[{b, a}] = i + 1; 

          st.insert({c, i + 1});
      }
}

int getMinimumFuelCapacity(int X, int Y) {
   X++;
  Y++;
  if(x <= 3)
      return -1;
  int mx = 0;
  if(X != 1) mx = mp[{1, X}];
  if(Y != 1) mx = max(mx, mp[{1, Y}]);


  if(X != 1) st.erase({mp[{1, X}], pos[{1, X}]});
  if(Y != 1) st.erase({mp[{1, Y}], pos[{1, Y}]});
  
  pair<int, int> p = *st.begin();
  st.erase(st.begin());
  if(X != 1 && Y != 1){
      st.insert(p);
      if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
      if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
      return max(mx, p.first);
  }
  else{
      pair<int, int> p1 = *st.begin();
      st.insert(p1);
      st.insert(p);
      if(X != 1) st.insert({mp[{1, X}], pos[{1, X}]});
      if(Y != 1) st.insert({mp[{1, Y}], pos[{1, Y}]});
      return max({mx, p.first, p1.first});
  }
}

Compilation message

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:64:41: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   64 |       return max({mx, p.first, p1.first});
      |                                         ^
In file included from /usr/include/c++/10/vector:60,
                 from swap.h:1,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
swap.cpp:64:41: note:   candidate expects 2 arguments, 1 provided
   64 |       return max({mx, p.first, p1.first});
      |                                         ^
In file included from /usr/include/c++/10/vector:60,
                 from swap.h:1,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
swap.cpp:64:41: note:   candidate expects 3 arguments, 1 provided
   64 |       return max({mx, p.first, p1.first});
      |                                         ^