Submission #172234

# Submission time Handle Problem Language Result Execution time Memory
172234 2019-12-31T18:27:02 Z emil_physmath Hard route (IZhO17_road) C++17
Compilation error
0 ms 0 KB
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
typedef long long llong;
const int maxN = 500005;

vector<int> nei[maxN];
pair<int, int> ray[maxN][3];

inline ostream& operator<<(ostream& ostr, const pair<int, int>& a)
{
    return ostr << "{" << a.first << ", " << a.second << "}";
}
inline const pair<int, int>& Second(const pair<int, int>* a)
{
    return a[0].second >= 2 ? a[0] : a[1];
}
void Maximize(pair<int, int>* a, pair<int, int> x)
{
    if (a[0].first == x.first)
        a[0].second += x.second;
    else if (a[1].first == x.first)
        a[1].second += x.second;
    else if (a[2].first == x.first)
        a[2].second += x.second;
    else if (x.first > a[2].first)
    {
        a[2] = x;
        sort(a, a + 3, greater<pair<int, int>>());
    }
}
void SetDown(int v, int par)
{
    fill(ray[v], ray[v] + 3, make_pair(0, 0));
    ray[v][0] = {0, 1};
    for (int to: nei[v])
        if (to != par)
        {
            SetDown(to, v);
            Maximize(ray[v], {ray[to][0].first + 1, 1});
        }
}
void SetUp(int v, int par)
{
    for (int to: nei[v])
        if (to != par)
        {
            // Set up[to].
            if (ray[v][0].first == ray[to][0].first + 1)
                Maximize(ray[to], {Second(ray[v]).first + 1, 1});
            else
                Maximize(ray[to], {ray[v][0].first + 1, 1});
            SetUp(to, v);
        }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; ++i)
    {
        int u, v;
        cin >> u >> v;
        nei[u].push_back(v);
        nei[v].push_back(u);
    }
    SetDown(1, -1);
    /*for (int v = 1; v <= n; ++v)
        cerr << v << ": " << ray[v][0] << ' ' << ray[v][1] << ' ' << ray[v][2] << endl;*/
    SetUp(1, -1);
    map<llong, llong> ans;
    for (int v = 1; v <= n; ++v)
    {
        // cerr << v << ": " << ray[v][0] << ' ' << ray[v][1] << ' ' << ray[v][2] << endl;
        vector<llong> x;
        vector<llong> y;
        for (int i = 0; i < 3; ++i)
            if (ray[v][i].first)
            {
                y.push_back(ray[v][i].second);
                for (int j = 0; j < min(3, y.back()); ++j)
                    x.push_back(ray[v][i].first);
            }
        if (x.size() < 3) continue;
        int cnt = 0;
        if (y[0] == 1)
        {
            if (y[1] == 1)
                cnt = y[1] * y[2];
            else
                cnt = (y[1] * (y[1] - 1)) / 2;
        }
        else
        {
            if (y[0] >= 3)
                cnt = (y[0] * (y[0] - 1)) / 2;
            else
                cnt = y[1];
        }
        ans[x[0] * (x[1] + x[2])] += cnt;
    }
    /*for (auto it: ans)
        cerr << it.first << ' ' << it.second << endl;*/
    if (ans.size())
        cout << ans.rbegin()->first << ' ' << ans.rbegin()->second << endl;
    else
        cout << "0 1";
}

Compilation message

road.cpp: In function 'int main()':
road.cpp:85:52: error: no matching function for call to 'min(int, __gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type&)'
                 for (int j = 0; j < min(3, y.back()); ++j)
                                                    ^
In file included from /usr/include/c++/7/algorithm:61:0,
                 from road.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
road.cpp:85:52: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}')
                 for (int j = 0; j < min(3, y.back()); ++j)
                                                    ^
In file included from /usr/include/c++/7/algorithm:61:0,
                 from road.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
road.cpp:85:52: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}')
                 for (int j = 0; j < min(3, y.back()); ++j)
                                                    ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from road.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
road.cpp:85:52: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 for (int j = 0; j < min(3, y.back()); ++j)
                                                    ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from road.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
road.cpp:85:52: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 for (int j = 0; j < min(3, y.back()); ++j)
                                                    ^