제출 #784665

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

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

vector<pair<int, int>> g[200005];
bool processed[200005];
int sz[200005];

int getSize(int cur, int par = -1) {
    sz[cur] = 1;
    for (auto next : g[cur]) {
        if (next.first != par && !processed[next.first]) sz[cur] += getSize(next.first, cur);
    }
    return sz[cur];
}

int getCentroid(int cur, int des, int par = -1) {
    for (auto next : g[cur]) {
        if (next.first != par && !processed[cur] && sz[cur] > des / 2) return getCentroid(next.first, des, cur);
    }
    return cur;
}

int ans = 10e7, k;

map<int, int> cnt;
set<int> s;

void solve(int cur, int par, int depth, int sum, bool t) {
    if (sum > k || depth >= ans) return;
    if (sum == k) {
        ans = depth;
        return;
    }
    s.insert(sum);
    if (!t) if (cnt.count(k - sum)) ans = min(ans, depth + cnt[k - sum]);
    else cnt[sum] = min(cnt[sum], depth);
    for (auto next : g[cur]) {
        if (next.first != par && !processed[next.first] && sum + next.second <= k) {
            solve(next.first, cur, depth + 1, sum + next.second, t);
        }
    }
}

void decompose(int cur = 0) {
    getSize(cur);
    cur = getCentroid(cur, getSize(cur));
    processed[cur] = 1;
    for (auto next : g[cur]) {
        if (!processed[next.first] && next.second <= k) {
            solve(cur, -1, 1, next.second, 0);
            solve(cur, -1, 1, next.second, 1);
        }
    }
    for (auto x : s) cnt.clear(x);
    s.clear();
    for (auto next : g[cur]) {
        if (!processed[next.first]) decompose(next.first);
    }
}

int best_path(int N, int K, int H[][2], int L[]) {
    k = K;
    for (int i = 0; i < N - 1; i++) {
        g[H[i][0]].push_back({H[i][1], L[i]});
        g[H[i][1]].push_back({H[i][0], L[i]});
    } 
    decompose();
    if (ans == 10e7) return -1;
    else return ans;
}

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

race.cpp: In function 'void solve(int, int, int, int, bool)':
race.cpp:41:8: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   41 |     if (!t) if (cnt.count(k - sum)) ans = min(ans, depth + cnt[k - sum]);
      |        ^
race.cpp: In function 'void decompose(int)':
race.cpp:60:33: error: no matching function for call to 'std::map<int, int>::clear(int&)'
   60 |     for (auto x : s) cnt.clear(x);
      |                                 ^
In file included from /usr/include/c++/10/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_map.h:1133:7: note: candidate: 'void std::map<_Key, _Tp, _Compare, _Alloc>::clear() [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
 1133 |       clear() _GLIBCXX_NOEXCEPT
      |       ^~~~~
/usr/include/c++/10/bits/stl_map.h:1133:7: note:   candidate expects 0 arguments, 1 provided