Submission #784672

#TimeUsernameProblemLanguageResultExecution timeMemory
784672vjudge1Race (IOI11_race)C++17
Compilation error
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;

int depths[200005]{10e7};
set<int> s;
unordered_map<int, int> hash;

void solve(int cur, int par, int depth, int sum, int t) {
    if (sum > k || depth >= ans) return;
    if (sum == k) {
        ans = depth;
        return;
    }
    if (t == 0 && hash.count(k - sum)) ans = min(ans, depth + depths[hash[k - sum]]);
    if (t == 1) depths[hash[sum]] = min(depths[hash[sum]], depth);
    if (t == 2) s.insert(sum);
    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(next.first, -1, 1, next.second, 2);
    }
    int cnt = 0;
    for (auto x : s) hash[x] = cnt++;
    for (auto next : g[cur]) {
        if (!processed[next.first] && next.second <= k) {
            solve(next.first, -1, 1, next.second, 0);
            solve(next.first, -1, 1, next.second, 1);
        }
    }
    for (auto x : s) depths[x] = 10e7;
    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;
    ans = N;
    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 == N) return -1;
    else return ans;
}

Compilation message (stderr)

race.cpp:31:24: error: narrowing conversion of '1.0e+8' from 'double' to 'int' [-Wnarrowing]
   31 | int depths[200005]{10e7};
      |                        ^
race.cpp: In function 'void solve(int, int, int, int, int)':
race.cpp:41:19: error: reference to 'hash' is ambiguous
   41 |     if (t == 0 && hash.count(k - sum)) ans = min(ans, depth + depths[hash[k - sum]]);
      |                   ^~~~
In file included from /usr/include/c++/10/string_view:42,
                 from /usr/include/c++/10/bits/basic_string.h:48,
                 from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/functional_hash.h:58:12: note: candidates are: 'template<class _Tp> struct std::hash'
   58 |     struct hash;
      |            ^~~~
race.cpp:33:25: note:                 'std::unordered_map<int, int> hash'
   33 | unordered_map<int, int> hash;
      |                         ^~~~
race.cpp:41:70: error: reference to 'hash' is ambiguous
   41 |     if (t == 0 && hash.count(k - sum)) ans = min(ans, depth + depths[hash[k - sum]]);
      |                                                                      ^~~~
In file included from /usr/include/c++/10/string_view:42,
                 from /usr/include/c++/10/bits/basic_string.h:48,
                 from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/functional_hash.h:58:12: note: candidates are: 'template<class _Tp> struct std::hash'
   58 |     struct hash;
      |            ^~~~
race.cpp:33:25: note:                 'std::unordered_map<int, int> hash'
   33 | unordered_map<int, int> hash;
      |                         ^~~~
race.cpp:42:24: error: reference to 'hash' is ambiguous
   42 |     if (t == 1) depths[hash[sum]] = min(depths[hash[sum]], depth);
      |                        ^~~~
In file included from /usr/include/c++/10/string_view:42,
                 from /usr/include/c++/10/bits/basic_string.h:48,
                 from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/functional_hash.h:58:12: note: candidates are: 'template<class _Tp> struct std::hash'
   58 |     struct hash;
      |            ^~~~
race.cpp:33:25: note:                 'std::unordered_map<int, int> hash'
   33 | unordered_map<int, int> hash;
      |                         ^~~~
race.cpp:42:48: error: reference to 'hash' is ambiguous
   42 |     if (t == 1) depths[hash[sum]] = min(depths[hash[sum]], depth);
      |                                                ^~~~
In file included from /usr/include/c++/10/string_view:42,
                 from /usr/include/c++/10/bits/basic_string.h:48,
                 from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/functional_hash.h:58:12: note: candidates are: 'template<class _Tp> struct std::hash'
   58 |     struct hash;
      |            ^~~~
race.cpp:33:25: note:                 'std::unordered_map<int, int> hash'
   33 | unordered_map<int, int> hash;
      |                         ^~~~
race.cpp: In function 'void decompose(int)':
race.cpp:59:22: error: reference to 'hash' is ambiguous
   59 |     for (auto x : s) hash[x] = cnt++;
      |                      ^~~~
In file included from /usr/include/c++/10/string_view:42,
                 from /usr/include/c++/10/bits/basic_string.h:48,
                 from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:1:
/usr/include/c++/10/bits/functional_hash.h:58:12: note: candidates are: 'template<class _Tp> struct std::hash'
   58 |     struct hash;
      |            ^~~~
race.cpp:33:25: note:                 'std::unordered_map<int, int> hash'
   33 | unordered_map<int, int> hash;
      |                         ^~~~