제출 #418573

#제출 시각아이디문제언어결과실행 시간메모리
418573snasibov05경주 (Race) (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
#include "race.h"
#include <vector>

using namespace std;

#define oo 1000000000
#define pii pair<int, int>
#define pb push_back
#define f first
#define s second

vector<vector<pii>> ed;
vector<vector<vector<int>>> dp;

void dfs(int cur, int pr, int k){
    dp[cur][0][0] = dp[cur][0][1] = 0;
    for (auto [to, dist] : ed[cur]){
        if (to == pr) continue;
        dfs(to, cur, k);
        for (int i = 0; i <= k; ++i) {
            dp[cur][i][0] = min({dp[cur][i][0], dp[to][i][0], dp[to][i][1]});
            if (i - dist >= 0) dp[cur][i][1] = min(dp[cur][i][1], dp[to][i - dist][1] + 1);
        }
    }

}

int best_path(int n, int k, int h[][2], int l[]){
    ed.resize(n);
    dp.resize(n);
    dp.assign(n, vector<vector<int>>(k+1, vector<int>(2, oo)));
    for (int i = 0; i < n - 1; ++i) {
        ed[h[i][0]].pb({h[i][1], l[i]});
        ed[h[i][1]].pb({h[i][0], l[i]});
    }
    dfs(0, -1, k);
    if (dp[0][k][0] == oo) dp[0][k][0] = -1;

    return dp[0][k][0];

}

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In function 'void dfs(int, int, int)':
race.cpp:17:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   17 |     for (auto [to, dist] : ed[cur]){
      |               ^
race.cpp:21:76: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   21 |             dp[cur][i][0] = min({dp[cur][i][0], dp[to][i][0], dp[to][i][1]});
      |                                                                            ^
In file included from /usr/include/c++/10/vector:60,
                 from race.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
race.cpp:21:76: note:   candidate expects 2 arguments, 1 provided
   21 |             dp[cur][i][0] = min({dp[cur][i][0], dp[to][i][0], dp[to][i][1]});
      |                                                                            ^
In file included from /usr/include/c++/10/vector:60,
                 from race.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
race.cpp:21:76: note:   candidate expects 3 arguments, 1 provided
   21 |             dp[cur][i][0] = min({dp[cur][i][0], dp[to][i][0], dp[to][i][1]});
      |                                                                            ^