#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int n;
int cnt=0,idx=0,tmp=0;
int pw(int a,int b){
int ans=1;
while(b){
if(b&1){
ans=ans*a%mod;
}
b>>=1;
a=a*a%mod;
}
return ans;
}
vector<vector<int>> adj;
vector<int> dp;
void dfs(int k,int pa){
bool flag=0;
for(int j:adj[k]){
if(j==pa){
continue;
}
dfs(j,k);
if(dp[j]==0){
flag=1;
}
}
if(k==idx&&tmp==1){
flag=1;
}
dp[k]=flag;
}
signed main(){
cin>>n;
int d;cin>>d;
if(n==2){
int p=pw(2,d*2);
cout<<p<<endl;
return 0;
}
adj.resize(n*2);
for(int i=1;i<n;i++){
int a,b;cin>>a>>b;a--;b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
for(int i=0;i<n;i++){
dp.assign(n,-1);
dfs(i,i);
if(dp[i]==1){
cnt++;
}
}
int ans=0;
for(int i=0;i<n;i++){
idx=i;
dp.assign(n,-1);
tmp=0;
dfs(0,0);
if(dp[0]==1){
ans+=cnt;
}
dp.assign(n,-1);
tmp=1;
dfs(0,0);
if(dp[0]==1){
ans+=n-cnt;
}
}
cout<<ans%mod<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
39 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
46 ms |
340 KB |
Output is correct |
8 |
Correct |
54 ms |
340 KB |
Output is correct |
9 |
Correct |
34 ms |
340 KB |
Output is correct |
10 |
Correct |
50 ms |
340 KB |
Output is correct |
11 |
Correct |
46 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
46 ms |
340 KB |
Output is correct |
8 |
Correct |
54 ms |
340 KB |
Output is correct |
9 |
Correct |
34 ms |
340 KB |
Output is correct |
10 |
Correct |
50 ms |
340 KB |
Output is correct |
11 |
Correct |
46 ms |
340 KB |
Output is correct |
12 |
Execution timed out |
1076 ms |
15212 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
46 ms |
340 KB |
Output is correct |
8 |
Correct |
54 ms |
340 KB |
Output is correct |
9 |
Correct |
34 ms |
340 KB |
Output is correct |
10 |
Correct |
50 ms |
340 KB |
Output is correct |
11 |
Correct |
46 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Incorrect |
40 ms |
304 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
46 ms |
340 KB |
Output is correct |
8 |
Correct |
54 ms |
340 KB |
Output is correct |
9 |
Correct |
34 ms |
340 KB |
Output is correct |
10 |
Correct |
50 ms |
340 KB |
Output is correct |
11 |
Correct |
46 ms |
340 KB |
Output is correct |
12 |
Execution timed out |
1076 ms |
15212 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
39 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |