Submission #413406

# Submission time Handle Problem Language Result Execution time Memory
413406 2021-05-28T16:53:46 Z souvenir_vayne Factories (JOI14_factories) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "factories.h"
#define pb push_back
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;

const int MAXN = 5e5+5;
ll anc[MAXN][22], al[MAXN], h[MAXN], pai[MAXN], sz[MAXN], used[MAXN], best[MAXN];
vector<pii> g[MAXN];

int getsz(int u, int p) {
    sz[u] = 1;
    for(pii &i : g[u])
        if(i.f != p && !used[i.f])
            sz[u] += getsz(i.f, u);
    return sz[u];
}

int findc(int u, int p, int n) {
    for(pii &i : g[u])
        if(i.f != p && !used[i.f] && sz[i.f] > n/2)
            return findc(i.f, u, n);
    return u;
}

void build(int u, int p) {
    int c = findc(u, -1, getsz(u, -1));
    used[c] = 1;
    pai[c] = p;

    for(pii &i : g[c])
        if(!used[i.f])
            build(i.f, c);
}

void dfs(int u) {

    for(pii &i : g[u])
        if(i.f != anc[u][0]) {
            anc[i.f][0] = u;
            al[i.f] = al[u] + 1;
            h[i.f] = h[u] + i.s;
            dfs(i.f);
        }
}

int getlca(int a, int b) {
    if(al[a] < al[b])
        swap(a, b);
    for(int i = 0; i <= 20; i++)
        if( (1<<i) & (al[b] - al[a]) )
            a = anc[a][i];

    if(a == b)
        return a;

    for(int i = 20; i >= 0; i--)
        if(anc[a][i] != anc[b][i])
            a = anc[a][i], b = anc[b][i];

    return anc[a][0];

}

int dist(int a, int b) {
    return h[a] + h[b] - 2*h[getlca(a, b)];
}

void update(int u) {
    int aux = u;
    while(u != -1) {
        best[u] = min(best[u], dist(aux, u));
        //debug2(u, best[u]);
        u = pai[u];
    }
}

int query(int u) {
    int aux = u, ans = LINF;
    while(u != -1) {
        ans = min(ans, best[u] + dist(aux, u));
        u = pai[u];
    }
    return ans;
}

void reset(int u) {
    while(u != -1) {
        best[u] = LINF;
        u = pai[u];
    }
}

void Init(int n, int a[], int b[], int c[]) {
    for(int i = 0; i < n; i++)
        best[i] = LINF;

    for(int i = 0; i < n-1; i++) {
        g[a[i]].pb({b[i], c[i]});
        g[b[i]].pb({a[i], c[i]});
    }

    dfs(0);
    for(int j = 1; j < 22; j++)
        for(int i = 1; i <= n; i++)
            anc[i][j] = anc[anc[i][j-1]][j-1];
    build(0, -1);
}

long long Query(int s, int x[], int t, int y[]) {

    int ans = LINF;
    for(int i = 0; i < s; i++)
        update(x[i]);
    for(int i = 0; i < t; i++)
        ans = min(ans, query(y[i]));
    for(int i = 0; i < s; i++)
        reset(x[i]);
    return ans;
}

Compilation message

factories.cpp: In function 'void update(int)':
factories.cpp:77:44: error: no matching function for call to 'min(long long int&, int)'
   77 |         best[u] = min(best[u], dist(aux, u));
      |                                            ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 factories.cpp:1:
/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:
factories.cpp:77:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   77 |         best[u] = min(best[u], dist(aux, u));
      |                                            ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 factories.cpp:1:
/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:
factories.cpp:77:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   77 |         best[u] = min(best[u], dist(aux, u));
      |                                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:1:
/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:
factories.cpp:77:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   77 |         best[u] = min(best[u], dist(aux, u));
      |                                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:1:
/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:
factories.cpp:77:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   77 |         best[u] = min(best[u], dist(aux, u));
      |                                            ^
factories.cpp: In function 'int query(int)':
factories.cpp:4:14: warning: overflow in conversion from 'long int' to 'int' changes value from '4557430888798830399' to '1061109567' [-Woverflow]
    4 | #define LINF 0x3f3f3f3f3f3f3f3f
      |              ^~~~~~~~~~~~~~~~~~
factories.cpp:84:24: note: in expansion of macro 'LINF'
   84 |     int aux = u, ans = LINF;
      |                        ^~~~
factories.cpp:86:46: error: no matching function for call to 'min(int&, long long int)'
   86 |         ans = min(ans, best[u] + dist(aux, u));
      |                                              ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 factories.cpp:1:
/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:
factories.cpp:86:46: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   86 |         ans = min(ans, best[u] + dist(aux, u));
      |                                              ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 factories.cpp:1:
/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:
factories.cpp:86:46: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   86 |         ans = min(ans, best[u] + dist(aux, u));
      |                                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:1:
/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:
factories.cpp:86:46: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   86 |         ans = min(ans, best[u] + dist(aux, u));
      |                                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from factories.cpp:1:
/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:
factories.cpp:86:46: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   86 |         ans = min(ans, best[u] + dist(aux, u));
      |                                              ^
factories.cpp: In function 'long long int Query(int, int*, int, int*)':
factories.cpp:4:14: warning: overflow in conversion from 'long int' to 'int' changes value from '4557430888798830399' to '1061109567' [-Woverflow]
    4 | #define LINF 0x3f3f3f3f3f3f3f3f
      |              ^~~~~~~~~~~~~~~~~~
factories.cpp:117:15: note: in expansion of macro 'LINF'
  117 |     int ans = LINF;
      |               ^~~~