QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#299065#7895. Graph Partitioning 2ucup-team203#Compile Error//C++201.6kb2024-01-06 17:01:372024-01-06 17:01:37

Judging History

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

  • [2024-01-06 17:01:37]
  • 评测
  • [2024-01-06 17:01:37]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
// tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> s;
using namespace __gnu_pbds;
using i64 = long long;
using namespace std;
const int N = 1e5 + 5;
// const int B = 340;
// const int M = 5e3 + 5;
// const int base = 1753591;
const int mod = 998244353;
// const int mod = 1e9 + 7;
// const double pi = acos(-1);

int n, k;
vector<int> adj[N];
unordered_map<int, int> dp[N];
void dfs(int cur, int fa)
{
    dp[cur][1] = 1;
    for (int i : adj[cur])
    {
        if (i == fa)
            continue;
        dfs(i, cur);
        map<int, int> tmp;
        for (auto &[u, g] : dp[cur])
        {
            for (auto &[v, f] : dp[i])
            {
                if (u + v <= k + 1)
                    tmp[u + v] = (tmp[u + v] + (i64)f * g % mod) % mod;
                if (v == k || v == k + 1)
                    tmp[u] = (tmp[u] + (i64)f * g % mod) % mod;
            }
        }
        dp[cur] = tmp;
    }
}
void solve()
{
    cin >> n >> k;
    for (int i = 1, u, v; i < n; i++)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, 0);
    cout << (dp[1][k] + dp[1][k + 1]) % mod << '\n';
    for (int i = 1; i <= n; i++)
        dp[i].clear(), adj[i].clear();
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    cout << fixed << setprecision(10);
    while (t--)
        solve();
}

詳細信息

answer.code: In function ‘void dfs(int, int)’:
answer.code:38:19: error: no match for ‘operator=’ (operand types are ‘std::unordered_map<int, int>’ and ‘std::map<int, int>’)
   38 |         dp[cur] = tmp;
      |                   ^~~
In file included from /usr/include/c++/11/unordered_map:47,
                 from /usr/include/c++/11/functional:61,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from answer.code:1:
/usr/include/c++/11/bits/unordered_map.h:272:7: note: candidate: ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(const std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&) [with _Key = int; _Tp = int; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, int> >]’
  272 |       operator=(const unordered_map&) = default;
      |       ^~~~~~~~
/usr/include/c++/11/bits/unordered_map.h:272:17: note:   no known conversion for argument 1 from ‘std::map<int, int>’ to ‘const std::unordered_map<int, int>&’
  272 |       operator=(const unordered_map&) = default;
      |                 ^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/unordered_map.h:276:7: note: candidate: ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&&) [with _Key = int; _Tp = int; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, int> >]’
  276 |       operator=(unordered_map&&) = default;
      |       ^~~~~~~~
/usr/include/c++/11/bits/unordered_map.h:276:17: note:   no known conversion for argument 1 from ‘std::map<int, int>’ to ‘std::unordered_map<int, int>&&’
  276 |       operator=(unordered_map&&) = default;
      |                 ^~~~~~~~~~~~~~~
/usr/include/c++/11/bits/unordered_map.h:290:7: note: candidate: ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(std::initializer_list<typename std::_Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc, std::__detail::_Select1st, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__is_nothrow_invocable<const _Hash&, const _Key&> > >::value, false, true> >::value_type>) [with _Key = int; _Tp = int; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, int> >; typename std::_Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc, std::__detail::_Select1st, _Pred, _Hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<std::__not_<std::__and_<std::__is_fast_hash<_Hash>, std::__is_nothrow_invocable<const _Hash&, const _Key&> > >::value, false, true> >::value_type = std::pair<const int, int>]’
  290 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/11/bits/unordered_map.h:290:46: note:   no known conversion for argument 1 from ‘std::map<int, int>’ to ‘std::initializer_list<std::pair<const int, int> >’
  290 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~