QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639084#7895. Graph Partitioning 2Forza_FerrariTL 2ms11480kbC++141.5kb2024-10-13 17:51:182024-10-13 17:51:19

Judging History

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

  • [2024-10-13 17:51:19]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:11480kb
  • [2024-10-13 17:51:18]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int block=400,mod=998244353;
int t,n,m;
vector<int> v[100001];
inline void init()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
inline int read()
{
    int x;
    cin>>x;
    return x;
}
inline int Mod(int x)
{
    return x>=mod? x-mod:x;
}
namespace sub1
{
    unordered_map<int,int> dp[100001];
    int s[100001];
    inline void dfs(int k,int f)
    {
        dp[k][1]=s[k]=1;
        for(int i:v[k])
        {
            if(i==f)
                continue;
            dfs(i,k);
            s[k]+=s[i];
            auto tmp=dp[k];
            dp[k].clear();
            for(auto l:tmp)
                for(auto r:dp[i])
                    dp[k][l.first+r.first]=Mod(dp[k][l.first+r.first]+1ll*l.second*r.second%mod);
        }
        dp[k][0]=Mod(dp[k][m]+dp[k][m+1]);
        dp[k].erase(m+1);
    }
    inline void main()
    {
        for(int i=1;i<=n;++i)
        {
            s[i]=0;
            dp[i].clear();
        }
        dfs(1,0);
        cout<<dp[1][0]<<'\n';
    }
}
int main()
{
    init();
    t=read();
    while(t--)
    {
        n=read(),m=read();
        for(int i=1;i<=n;++i)
            v[i].clear();
        for(int i=1;i<n;++i)
        {
            int x=read(),y=read();
            v[x].emplace_back(y);
            v[y].emplace_back(x);
        }
        sub1::main();
    }
    cout.flush();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 11480kb

input:

2
8 2
1 2
3 1
4 6
3 5
2 4
8 5
5 7
4 3
1 2
1 3
2 4

output:

2
1

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

5550
13 4
10 3
9 1
10 8
3 11
8 5
10 7
9 6
13 5
9 7
2 7
5 12
4 8
8 2
4 1
3 4
7 8
2 5
6 7
4 8
2 3
11 1
11 10
1 4
9 10
8 4
3 6
5 7
6 1
10 2
11 7
11 1
17 2
14 16
13 15
17 3
15 11
1 6
13 2
13 17
4 8
14 10
8 14
14 5
9 12
14 2
12 17
17 6
15 7
14 6
2 14
2 13
2 4
8 4
3 11
7 3
14 1
11 9
13 3
5 10
6 8
3 10
14 ...

output:

0
3
112
0
1
0
1
0
0
0
1
0
1
0
0
1
0
140
0
0
0
814
1
6
1
1
2
2
0
612
0
1
0
0
0
1
1
0
0
121
4536
0
0
1718
0
0
1
0
444
1
1908
1813
3
74
0
1
0
46
0
0
0
0
0
0
0
0
0
1
0
1
1
1
239
0
0
0
1
0
0
0
1
0
1
0
0
1
1
0
0
0
1
0
0
0
48
0
2
0
0
0
1
364
0
206
0
0
76
0
1
0
0
2
0
1
2
0
0
1
0
0
4
0
1
1
0
0
1
1
1
0
0
1
1
...

result: