QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278664#7895. Graph Partitioning 2ucup-team956Compile Error//C++201.7kb2023-12-07 19:08:072023-12-07 19:08:08

Judging History

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

  • [2023-12-07 19:08:08]
  • 评测
  • [2023-12-07 19:08:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define time chrono::system_clock::now().time_since_epoch().count()
mt19937_64 rnd(time);
#define maxn 1000005
#define int long long

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;

int read() {int x;cin>>x;return x;}
const int mod = 998244353;

void solve() {
    int n = read(), k = read();
    vector<vector<int>>g(n + 1);
    for(int i = 1; i < n; i++) {
        int aa = read(), bb = read();
        g[aa].push_back(bb);
        g[bb].push_back(aa);
    }
    int ok = 1;
    vector<gp_hash_table<int,int>>f(n + 1);
    // vector f(n + 1, vector(3, 0ll));
    // 0:1    1:k + 1    2:sz
    vector sz(n + 1, 0ll);
    auto dfs = [&](auto dfs, int x, int fa) -> void {
        f[x][1] = 1;
        for(int i : g[x]) {
            if(i == fa) continue;
            dfs(dfs, i, x);
            gp_hash_table<int,int>ff;
            for(auto [key, val] : f[x]) {
                if(val == 0) continue;
                for(auto [k1, v1] : f[i]) {
                    if(v1 == 0) continue;
                    if(k1 + key <= k + 1) {
                        ff[k1 + key] = (ff[k1 + key] + (v1 * val)) % mod;
                    }
                    if(k1 >= k) {
                        ff[key] = (ff[key] + val * v1) % mod;
                    }
                }
            }
            f[x] = ff;
        }
    };

    dfs(dfs, 1, 0);
    cout << (f[1][k] + f[1][k + 1]) % mod << "\n";
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    int t = read();
    while(t--) solve();
    return 0;
}

Details

In file included from /usr/include/c++/11/ext/pb_ds/detail/type_utils.hpp:47,
                 from /usr/include/c++/11/ext/pb_ds/tag_and_trait.hpp:46,
                 from /usr/include/c++/11/ext/pb_ds/assoc_container.hpp:46,
                 from answer.code:8:
/usr/include/c++/11/tr1/type_traits:121:3: error: redefinition of ‘struct std::tr1::__is_integral_helper<long long int>’
  121 |   _DEFINE_SPEC(0, __is_integral_helper, long long, true)
      |   ^
/usr/include/c++/11/tr1/type_traits:117:3: note: previous definition of ‘struct std::tr1::__is_integral_helper<long long int>’
  117 |   _DEFINE_SPEC(0, __is_integral_helper, int, true)
      |   ^
/usr/include/c++/11/tr1/type_traits:122:3: error: redefinition of ‘struct std::tr1::__is_integral_helper<long long unsigned int>’
  122 |   _DEFINE_SPEC(0, __is_integral_helper, unsigned long long, true)
      |   ^
/usr/include/c++/11/tr1/type_traits:118:3: note: previous definition of ‘struct std::tr1::__is_integral_helper<long long unsigned int>’
  118 |   _DEFINE_SPEC(0, __is_integral_helper, unsigned int, true)
      |   ^
/usr/include/c++/11/tr1/type_traits:549:3: error: redefinition of ‘struct std::tr1::__is_signed_helper<long long int>’
  549 |   _DEFINE_SPEC(0, __is_signed_helper, long long, true)
      |   ^
/usr/include/c++/11/tr1/type_traits:547:3: note: previous definition of ‘struct std::tr1::__is_signed_helper<long long int>’
  547 |   _DEFINE_SPEC(0, __is_signed_helper, int, true)
      |   ^
/usr/include/c++/11/tr1/type_traits:564:3: error: redefinition of ‘struct std::tr1::__is_unsigned_helper<long long unsigned int>’
  564 |   _DEFINE_SPEC(0, __is_unsigned_helper, unsigned long long, true)
      |   ^
/usr/include/c++/11/tr1/type_traits:562:3: note: previous definition of ‘struct std::tr1::__is_unsigned_helper<long long unsigned int>’
  562 |   _DEFINE_SPEC(0, __is_unsigned_helper, unsigned int, true)
      |   ^
In file included from /usr/include/c++/11/tr1/functional:41,
                 from /usr/include/c++/11/ext/pb_ds/detail/standard_policies.hpp:51,
                 from /usr/include/c++/11/ext/pb_ds/assoc_container.hpp:47,
                 from answer.code:8:
/usr/include/c++/11/tr1/functional_hash.h:75:3: error: redefinition of ‘std::size_t std::tr1::hash<_Tp>::operator()(_Tp) const [with _Tp = long long int; std::size_t = long unsigned int]’
   75 |   _TR1_hashtable_define_trivial_hash(long long);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/tr1/functional_hash.h:73:3: note: ‘std::size_t std::tr1::hash<_Tp>::operator()(_Tp) const [with _Tp = long long int; std::size_t = long unsigned int]’ previously declared here
   73 |   _TR1_hashtable_define_trivial_hash(int);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/tr1/functional_hash.h:79:3: error: redefinition of ‘std::size_t std::tr1::hash<_Tp>::operator()(_Tp) const [with _Tp = long long unsigned int; std::size_t = long unsigned int]’
   79 |   _TR1_hashtable_define_trivial_hash(unsigned long long);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/tr1/functional_hash.h:77:3: note: ‘std::size_t std::tr1::hash<_Tp>::operator()(_Tp) const [with _Tp = long long unsigned int; std::size_t = long unsigned int]’ previously declared here
   77 |   _TR1_hashtable_define_trivial_hash(unsigned int);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp:193,
                 from /usr/include/c++/11/ext/pb_ds/detail/container_base_dispatch.hpp:72,
                 from /usr/include/c++/11/ext/pb_ds/assoc_container.hpp:48,
                 from answer.code:8:
/usr/include/c++/11/ext/pb_ds/detail/unordered_iterator/const_iterator.hpp: In instantiation of ‘class __gnu_pbds::detail::gp_ht_map<long long int, long long int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::const_iterator_’:
/usr/include/c++/11/ext/pb_ds/detail/unordered_iterator/iterator.hpp:47:7:   required from ‘class __gnu_pbds::detail::gp_ht_map<long long int, long long int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::iterator_’
/usr/include/c++/11/ext/pb_ds/detail/gp_hash_table_map_/iterator_fn_imps.hpp:46:1:   required from ‘class __gnu_pbds::detail::gp_ht_map<long long int, long long int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __g...