제출 #905078

#제출 시각아이디문제언어결과실행 시간메모리
905078a_l_i_r_e_z_a경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
// In the name of God

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())

const int maxn = 2e5 + 5, maxk = 1e6  + 5;
const int inf = 1e9 + 7;
ll n, k, ans = inf;
vector<pll> adj[maxn];
map<ll, ll> mn[maxn];

void dfs(int v = 0, int h = 0, ll d = 0, int p = -1){
    mn[v].insert(mp(d, h));
    for(auto [u, w]: adj[v]){
        if(u == p) continue;
        dfs(u, h + 1, d + w, v);
        if(mn[u].size() > mn[v].size()) swap(mn[u], mn[v]);
        for(auto w: mn[u]){
            ll x = k + 2 * d - w.F;
            auto it = mn[v].find(x);
            if(it != mn[v].end()) smin(ans, w.S + (*it).S - 2 * h);
        }
        for(auto w: mn[u]){
            auto it = mn[v].find(w.F);
            if(it != mn[v].end()) smin((*it).S, w.S);
            else mn[v].insert(w);
        }
    }
}

int best_path(int N, int K, int H[][2], int L[]){
    n = N, k = K;
    fill(mn, mn + maxk, inf);
    for(int i = 0; i < n - 1; i++){
        int u = H[i][0], v = H[i][1], w = L[i];
        adj[u].pb(mp(v, w));
        adj[v].pb(mp(u, w));
    }
    dfs();
    return (ans >= inf ? -1 : ans);
}

// int32_t main()
// {
//     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     cin >> n >> k;
//     for(int i = 0; i < n - 1; i++){
//         int u, v, w; cin >> u >> v >> w;
//         adj[u].pb(mp(v, w));
//         adj[v].pb(mp(u, w));
//     }
//     dfs();
//     cout << (ans >= inf ? -1 : ans) << '\n';

//     return 0;
// }

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

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: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = std::map<long long int, long long int>*; _Tp = int; typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/10/bits/stl_algobase.h:914:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = std::map<long long int, long long int>*; _Tp = int]'
/usr/include/c++/10/bits/stl_algobase.h:944:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = std::map<long long int, long long int>*; _Tp = int]'
race.cpp:47:28:   required from here
/usr/include/c++/10/bits/stl_algobase.h:873:11: error: no match for 'operator=' (operand types are 'std::map<long long int, long long int>' and 'const int')
  873 |  *__first = __tmp;
      |  ~~~~~~~~~^~~~~~~
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:3:
/usr/include/c++/10/bits/stl_map.h:319:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compare, _Alloc>::operator=(const std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >]'
  319 |       operator=(const map&) = default;
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:319:17: note:   no known conversion for argument 1 from 'const int' to 'const std::map<long long int, long long int>&'
  319 |       operator=(const map&) = default;
      |                 ^~~~~~~~~~
/usr/include/c++/10/bits/stl_map.h:323:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compare, _Alloc>::operator=(std::map<_Key, _Tp, _Compare, _Alloc>&&) [with _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >]'
  323 |       operator=(map&&) = default;
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:323:17: note:   no known conversion for argument 1 from 'const int' to 'std::map<long long int, long long int>&&'
  323 |       operator=(map&&) = default;
      |                 ^~~~~
/usr/include/c++/10/bits/stl_map.h:337:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>& std::map<_Key, _Tp, _Compare, _Alloc>::operator=(std::initializer_list<std::pair<const _Key, _Tp> >) [with _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >]'
  337 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:337:46: note:   no known conversion for argument 1 from 'const int' to 'std::initializer_list<std::pair<const long long int, long long int> >'
  337 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~