QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#818421#9881. Diverge and Convergeucup-team004Compile Error//C++233.8kb2024-12-17 20:10:552024-12-17 20:10:55

Judging History

你现在查看的是最新测评结果

  • [2024-12-17 20:10:55]
  • 评测
  • [2024-12-17 20:10:55]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;

std::array<int, 2> E(int u, int v) {
    if (u > v) {
        std::swap(u, v);
    }
    return {u, v};
}

std::array<std::vector<std::array<int, 2>>, 2> solve(int N, std::vector<std::array<int, 2>> e1, std::vector<std::array<int, 2>> e2) {
    if (e1.empty()) {
        return {};
    }
    std::vector<std::vector<int>> T1(N), T2(N);
    for (auto [u, v] : e1) {
        T1[u].push_back(v);
        T1[v].push_back(u);
    }
    for (auto [u, v] : e2) {
        T2[u].push_back(v);
        T2[v].push_back(u);
    }
    
    bool swapped = false;
    std::vector<std::array<int, 2>> a, b;
    for (int x = 0; x < N; x++) {
        if (T1[x].size() + T2[x].size() == 2) {
            int y = T1[x][0];
            int z = T2[x][0];
            e1.erase(std::find(e1.begin(), e1.end(), E(x, y)));
            e2.erase(std::find(e2.begin(), e2.end(), E(x, z)));
            std::tie(a, b) = solve(N, e1, e2);
            a.push_back(E(x, y));
            b.push_back(E(x, z));
            break;
        } else if (T1[x].size() + T2[x].size() == 3) {
            if (T1[x].size() == 2) {
                std::swap(T1, T2);
                std::swap(e1, e2);
                swapped = true;
            }
            int w = T1[x][0];
            int y = T2[x][0];
            int z = T2[x][1];
            e1.erase(std::find(e1.begin(), e1.end(), E(x, w)));
            e2.erase(std::find(e2.begin(), e2.end(), E(x, y)));
            e2.erase(std::find(e2.begin(), e2.end(), E(x, z)));
            e2.push_back(E(y, z));
            std::tie(a, b) = solve(N, e1, e2);
            
            int k = std::find(b.begin(), b.end(), E(y, z)) - b.begin();
            auto [u, v] = a[k];
            
            std::vector<std::vector<int>> T(N);
            for (int i = 0; i < a.size(); i++) {
                if (i != k) {
                    auto [u, v] = a[i];
                    T[u].push_back(v);
                    T[v].push_back(u);
                }
            }
            
            std::vector<bool> vis(N);
            auto dfs = [&](auto &&self, int x, int p) -> void {
                vis[x] = true;
                for (auto y : T[x]) {
                    if (y == p) {
                        continue;
                    }
                    self(self, y, x);
                }
            };
            dfs(dfs, u, -1);
            
            if (vis[w] == vis[y]) {
                b[k] = E(x, z);
                a.insert(a.begin() + k + 1, E(x, w));
                b.insert(b.begin() + k + 1, E(x, y));
            } else {
                b[k] = E(x, y);
                a.insert(a.begin() + k + 1, E(x, w));
                b.insert(b.begin() + k + 1, E(x, z));
            }
            break;
        }
    }
    
    if (swapped) {
        std::swap(a, b);
    }
    return {a, b};
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;
    std::cin >> N;
    
    std::vector<std::array<int, 2>> e1(N - 1), e2(N - 1);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        e1[i] = E(u, v);
    }
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        e2[i] = E(u, v);
    }
    
    auto [a, b] = solve(N, e1, e2);
    
    for (int i = 0; i < N - 1; i++) {
        std::cout << std::find(e1.begin(), e1.end(), a[i]) - e1.begin() + 1 << " \n"[i == N - 2];
    }
    for (int i = 0; i < N - 1; i++) {
        std::cout << std::find(e2.begin(), e2.end(), b[i]) - e2.begin() + 1 << " \n"[i == N - 2];
    }
    
    return 0;
}

詳細信息

answer.code: In function ‘std::array<std::vector<std::array<int, 2> >, 2> solve(int, std::vector<std::array<int, 2> >, std::vector<std::array<int, 2> >)’:
answer.code:37:45: error: no match for ‘operator=’ (operand types are ‘std::tuple<std::vector<std::array<int, 2>, std::allocator<std::array<int, 2> > >&, std::vector<std::array<int, 2>, std::allocator<std::array<int, 2> > >&>’ and ‘std::array<std::vector<std::array<int, 2> >, 2>’)
   37 |             std::tie(a, b) = solve(N, e1, e2);
      |                                             ^
In file included from /usr/include/c++/13/bits/uses_allocator_args.h:38,
                 from /usr/include/c++/13/bits/memory_resource.h:41,
                 from /usr/include/c++/13/string:58,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:1:
/usr/include/c++/13/tuple:1628:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::__enable_if_t<__assignable<const _U1&, const _U2&>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::tuple<_U1, _U2>&) [with _U2 = _U1; _T1 = std::vector<std::array<int, 2> >&; _T2 = std::vector<std::array<int, 2> >&]’
 1628 |         operator=(const tuple<_U1, _U2>& __in)
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1628:9: note:   template argument deduction/substitution failed:
answer.code:37:45: note:   ‘std::array<std::vector<std::array<int, 2> >, 2>’ is not derived from ‘const std::tuple<_T1, _T2>’
   37 |             std::tie(a, b) = solve(N, e1, e2);
      |                                             ^
/usr/include/c++/13/tuple:1638:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::__enable_if_t<__assignable<_U1, _U2>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::tuple<_U1, _U2>&&) [with _U2 = _U1; _T1 = std::vector<std::array<int, 2> >&; _T2 = std::vector<std::array<int, 2> >&]’
 1638 |         operator=(tuple<_U1, _U2>&& __in)
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1638:9: note:   template argument deduction/substitution failed:
answer.code:37:45: note:   ‘std::array<std::vector<std::array<int, 2> >, 2>’ is not derived from ‘std::tuple<_T1, _T2>’
   37 |             std::tie(a, b) = solve(N, e1, e2);
      |                                             ^
/usr/include/c++/13/tuple:1664:9: note: candidate: ‘template<class _U1, class _U2> constexpr const std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(const std::tuple<_U1, _U2>&) const requires (is_assignable_v<const _T1&, const _U1&>) && (is_assignable_v<const _T2&, const _U2&>) [with _U2 = _U1; _T1 = std::vector<std::array<int, 2> >&; _T2 = std::vector<std::array<int, 2> >&]’
 1664 |         operator=(const tuple<_U1, _U2>& __in) const
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1664:9: note:   template argument deduction/substitution failed:
answer.code:37:45: note:   ‘std::array<std::vector<std::array<int, 2> >, 2>’ is not derived from ‘const std::tuple<_T1, _T2>’
   37 |             std::tie(a, b) = solve(N, e1, e2);
      |                                             ^
/usr/include/c++/13/tuple:1674:9: note: candidate: ‘template<class _U1, class _U2> constexpr const std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(std::tuple<_U1, _U2>&&) const requires (is_assignable_v<const _T1&, _U1>) && (is_assignable_v<const _T2&, _U2>) [with _U2 = _U1; _T1 = std::vector<std::array<int, 2> >&; _T2 = std::vector<std::array<int, 2> >&]’
 1674 |         operator=(tuple<_U1, _U2>&& __in) const
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1674:9: note:   template argument deduction/substitution failed:
answer.code:37:45: note:   ‘std::array<std::vector<std::array<int, 2> >, 2>’ is not derived from ‘std::tuple<_T1, _T2>’
   37 |             std::tie(a, b) = solve(N, e1, e2);
      |                                             ^
/usr/include/c++/13/tuple:1686:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::__enable_if_t<__assignable<const _U1&, const _U2&>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = std::vector<std::array<int, 2> >&; _T2 = std::vector<std::array<int, 2> >&]’
 1686 |         operator=(const pair<_U1, _U2>& __in)
      |         ^~~~~~~~
/usr/include/c++/13/tuple:1686:9: note:   template argument deduction/substitution failed:
answer.code:37:45: note:   ‘std::array<std::vector<std::array<int, 2> >, 2>’ is not derived from ‘const std::pair<_T1, _T2>’
   37 |             std::tie(a, b) = solve(N, e1, e2);
      |                                             ^
/usr/include/c++/13/tuple:1697:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::__enable_if_t<__assignable<_U1, _U2>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = std::vector<std::array<int, 2> >&; _T2 = std::vector<std::array<int, 2> >&]’
 1697 |         opera...