Submission #862426

# Submission time Handle Problem Language Result Execution time Memory
862426 2023-10-18T08:14:37 Z The_Samurai Love Polygon (BOI18_polygon) C++17
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const int inf = 1e9;

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n, z = 0;
    cin >> n;
    if (n % 2) {
        cout << -1;
        return 0;
    }
    vector<pair<string, string>> adj(n);
    for (auto &it: adj) cin >> it.first >> it.second;
    map<string, int> mp;
    for (auto &it: adj) mp[it.first];
    for (auto &it: adj) mp[it.second];
    for (auto &it: mp) it.second = z++;
    set<pair<int, int>> st;
    vector<int> out(n), in(n);
    for (int i = 0; i < n; i++) out[mp[adj[i].first]] = mp[adj[i].second];
//    for (int i = 0; i < n; i++) cout << mp[adj[i].first] << ' ' << mp[adj[i].second] << endl;
    for (int i = 0; i < n; i++) in[out[i]]++;
//    for (int i = 0; i < n; i++) cout << in[i] << ' ';
//    cout << endl;
    auto solve = [&](vector<bool> &blocked) {
        for (int i = 0; i < n; i++) if (!blocked[i]) st.insert(make_pair(in[i], i));
        vector<bool> changed(n);
        int ans = 0;
        while (!st.empty()) {
            auto [c, u] = *st.begin(); st.erase(st.begin());
            if (u == out[u] or changed[out[u]]) continue;
            int v = out[u];
            if (u != out[v]) {
                st.erase(make_pair(in[out[v]], out[v]));
                in[out[v]]--;
                st.insert(make_pair(in[out[v]], out[v]));
                out[v] = u;
                ans++;
            }
            st.erase(make_pair(in[v], v));
            changed[u] = changed[v] = true;
        }
        return ans + count(changed.begin(), changed.end(), false) + count(blocked.begin(), blocked.end(), true);
    };
    vector<bool> blocked(n);
    ll ans = solve(blocked);
    in.assign(n, 0);
    for (int i = 0; i < n; i++) out[mp[adj[i].first]] = mp[adj[i].second];
    for (int i = 0; i < n; i++) in[out[i]]++;
    for (int i = 0; i < n; i++) if (!in[i]) blocked[i] = true;
    cout << min(ans, solve(blocked));
}

Compilation message

polygon.cpp: In function 'int main()':
polygon.cpp:59:36: error: no matching function for call to 'min(ll&, long int)'
   59 |     cout << min(ans, solve(blocked));
      |                                    ^
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 polygon.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:
polygon.cpp:59:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   59 |     cout << min(ans, solve(blocked));
      |                                    ^
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 polygon.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:
polygon.cpp:59:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   59 |     cout << min(ans, solve(blocked));
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from polygon.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:
polygon.cpp:59:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   59 |     cout << min(ans, solve(blocked));
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from polygon.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:
polygon.cpp:59:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   59 |     cout << min(ans, solve(blocked));
      |                                    ^