Submission #676715

#TimeUsernameProblemLanguageResultExecution timeMemory
676715d4xn경주 (Race) (IOI11_race)C++17
Compilation error
0 ms0 KiB
#pragma GCC optimize ("Ofast") #include "race.h" #include <bits/stdc++.h> using namespace std; #define ll long long const int N = 2e5+1, inf = LLONG_MAX; int n, k, sz[N]; ll ans; vector<pair<int, ll>> adj[N]; bitset<N> r; void dfs(int u, int par) { sz[u] = 1; for (auto &[v, w] : adj[u]) { if (v == par || r[v]) continue; dfs(v, u); sz[u] += sz[v]; } } int find_centroid(int u, int par, int rt) { for (auto &[v, w] : adj[u]) { if (v != par && !r[v] && sz[v] > sz[rt]/2) { return find_centroid(v, u, rt); } } return u; } void dfs2(int u, int par, int d, ll dw, map<ll, int> &dis) { if (dw > k || d >= ans) return; auto it = dis.find(dw); if (it == dis.end()) dis[dw] = d; else it->second = min(it->second, d); for (auto &[v, w] : adj[u]) { if (v == par || r[v]) continue; dfs2(v, u, d+1, dw+w, dis); } } void solve_centroid(int u) { map<ll, int> mnD; mnD[0] = 0; for (auto &[v, w] : adj[u]) { if (r[v]) continue; map<ll, int> mnD2; dfs2(v, u, 1, w, mnD2); if (mnD2.size() > mnD.size()) swap(mnD, mnD2); for (auto &[dw, d] : mnD2) { auto it = mnD.find(k-dw); if (it == mnD.end()) break; ans = min(ans, d+it->second); } for (auto &[dw, d] : mnD2) { auto it = mnD.find(dw); if (it == mnD.end()) mnD[dw] = d; else it->second = min(it->second, d); } } } void dec(int u) { dfs(u, u); int ct = find_centroid(u, u, u); r[ct] = 1; solve_centroid(ct); for (auto &[v, w] : adj[ct]) { if (r[v]) continue; dec(v); } } int best_path(int N, int K, int H[][2], int L[]) { ans = inf; n = N; k = K; for (int i = 0; i < n-1; i++) { adj[H[i][0]].push_back(make_pair(H[i][1], L[i])); adj[H[i][1]].push_back(make_pair(H[i][0], L[i])); } dec(0); return (ans == inf ? -1 : ans); }

Compilation message (stderr)

race.cpp:8:28: warning: overflow in conversion from 'long long int' to 'int' changes value from '9223372036854775807' to '-1' [-Woverflow]
    8 | const int N = 2e5+1, inf = LLONG_MAX;
      |                            ^~~~~~~~~
race.cpp: In function 'void solve_centroid(int)':
race.cpp:57:36: error: no matching function for call to 'min(long long int&, std::tuple_element<1, std::pair<const long long int, int> >::type)'
   57 |         ans = min(ans, d+it->second);
      |                                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from race.cpp:3:
/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:57:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::tuple_element<1, std::pair<const long long int, int> >::type' {aka 'int'})
   57 |         ans = min(ans, d+it->second);
      |                                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from race.cpp:3:
/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:57:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::tuple_element<1, std::pair<const long long int, int> >::type' {aka 'int'})
   57 |         ans = min(ans, d+it->second);
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
race.cpp:57:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   57 |         ans = min(ans, d+it->second);
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
race.cpp:57:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   57 |         ans = min(ans, d+it->second);
      |                                    ^