#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=1007;
ll n,m,k;
vector<int>g[N];
bool dp[N][N]; // i - root, j - vertex (0: mtnoxy krvuma, 1: mtnoxy kruma)
bool tmp[N];
int cnt[N][N];
int p[N];
ll binpow(ll x, ll y){
if(y==0)return 1;
if(y==1)return x;
if(y%2!=0)return (x*binpow(x,y-1))%MOD;
ll val=binpow(x,y/2);
return (val*val)%MOD;
}
void dfs(int root, int v, int par){
dp[root][v]=1;
cnt[root][v]=0;
if(root==1)p[v]=par;
for(int to:g[v]){
if(to!=par){
dfs(root,to,v);
if(dp[root][to]==1){
dp[root][v]=0;
cnt[root][v]++;
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt", "r", stdin);
cin>>n>>k;
for(int i=0;i<n-1;i++){
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
if(n==2){
cout<<binpow(4,k)<<endl;
return 0;
}
int c=0;
for(int v=1;v<=n;v++){
dfs(v,v,-1);
c+=dp[v][v];
}
ll ans=0;
for(int v=1;v<=n;v++){
// for(int u=1;u<=n;u++){
// cout<<dp[v][u]<<" ";
// }
// cout<<endl;
// for(int u=1;u<=n;u++){
// cout<<cnt[v][u]<<" ";
// }
// cout<<endl;
bool change=true;
bool cur=true;
int u=v;
while(u!=-1){
if((cnt[1][u]==1&&!cur)||(cnt[1][u]==0&&cur)){
cur=!cur;
u=p[u];
}
else{
change=false;
break;
}
}
if(!change){
ans+=n;
}
else {
ans+=(n-c);
}
}
if(dp[1][1]){
ans=n*n-ans;
}
cout<<ans%MOD<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
17 ms |
5212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
736 KB |
Output is correct |
7 |
Correct |
19 ms |
5320 KB |
Output is correct |
8 |
Correct |
22 ms |
5360 KB |
Output is correct |
9 |
Correct |
14 ms |
5296 KB |
Output is correct |
10 |
Correct |
16 ms |
5280 KB |
Output is correct |
11 |
Correct |
17 ms |
5268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
736 KB |
Output is correct |
7 |
Correct |
19 ms |
5320 KB |
Output is correct |
8 |
Correct |
22 ms |
5360 KB |
Output is correct |
9 |
Correct |
14 ms |
5296 KB |
Output is correct |
10 |
Correct |
16 ms |
5280 KB |
Output is correct |
11 |
Correct |
17 ms |
5268 KB |
Output is correct |
12 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
736 KB |
Output is correct |
7 |
Correct |
19 ms |
5320 KB |
Output is correct |
8 |
Correct |
22 ms |
5360 KB |
Output is correct |
9 |
Correct |
14 ms |
5296 KB |
Output is correct |
10 |
Correct |
16 ms |
5280 KB |
Output is correct |
11 |
Correct |
17 ms |
5268 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Incorrect |
15 ms |
5196 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
736 KB |
Output is correct |
7 |
Correct |
19 ms |
5320 KB |
Output is correct |
8 |
Correct |
22 ms |
5360 KB |
Output is correct |
9 |
Correct |
14 ms |
5296 KB |
Output is correct |
10 |
Correct |
16 ms |
5280 KB |
Output is correct |
11 |
Correct |
17 ms |
5268 KB |
Output is correct |
12 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
17 ms |
5212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |