# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
54511704 |
Practice:
mrmanunog |
426B
- 42
|
Mono C#
|
Compilation error
|
0 ms
|
0 KB
|
2019-05-23 10:29:10 |
2019-05-23 10:29:10 |
|
# include <bits/stdc++.h>
# define pb push_back
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
vector<int>g[503];
int n, m;
LL dp[503][20003];
inline void scan(int &ret)
{
char c; ret=0;
while((c=getchar())<'0'||c>'9');
while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();
}
inline void out(LL x)
{
if(x>9) out(x/10);
putchar(x%10+'0');
}
inline void add(LL &a, LL b)
{
a += b;
if(a >= mod) a -= mod;
}
inline void pro(LL &a, LL b)
{
a *= b;
if(a >= mod) a%=mod;
}
void dfs(int u, int pre)
{
for(auto v : g[u])
{
if(v == pre) continue;
dfs(v, u);
for(int i=1; i<=m; ++i)
{
LL sum = 0;
for(int j=i; j<=m; j+=i)
add(sum, dp[v][j]);
pro(dp[u][i], sum);
}
}
}
int main()
{
int T, a, b;
scan(T);
while(T--)
{
scan(n), scan(m);
for(int i=1; i<=n; ++i) g[i].clear();
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
dp[i][j] = 1LL;
for(int i=1; i<n; ++i)
{
scan(a), scan(b);
g[a].pb(b);
g[b].pb(a);
}
dfs(1, 0);
LL ans = 0;
for(int i=1; i<=m; ++i)
add(ans, dp[1][i]);
out(ans);
putchar('\n');
}
return 0;
}
---------------------
作者:junior19
来源:CSDN
原文:https://blog.csdn.net/junior19/article/details/77428019
版权声明:本文为博主原创文章,转载请附上博文链接!
Click to see test details