#include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define ROF(i, r, l) for(int i = (r)-1; i >= (l); --i)
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define sz(v) (int)v.size()
#define pb push_back
#define eb emplace_back
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(x) "[" #x " = " << (x) << "]"
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
typedef long long ll;
using db = double;
using ull = unsigned long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<db>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
void setIO(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
#endif
}
const int MAX = 1e5 + 5;
const int mod = 1e9 + 7;
struct mint{
int v;
mint(int v) : v(v) {}
mint& operator += (const mint& o){
v += o.v;
if(v >= mod) v -= mod;
return *this;
}
mint& operator -= (const mint& o){
v -= o.v;
if(v < 0) v += mod;
return *this;
}
mint& operator *= (const mint& o){
v = 1LL * v * o.v % mod;
return *this;
}
mint power(ll n) const {
mint res(1), base = *this;
for(; n > 0; n >>= 1, base *= base) if(n & 1) res *= base;
return res;
}
mint inv() const {
return power(mod - 2);
}
mint& operator /= (const mint& o){
return *this *= o.inv();
}
friend mint operator + (mint a, const mint& b){ return a += b; }
friend mint operator - (mint a, const mint& b){ return a -= b; }
friend mint operator * (mint a, const mint& b){ return a *= b; }
friend mint operator / (mint a, const mint& b){ return a /= b; }
friend ostream& operator << (ostream& out, const mint& o){ return out << o.v; }
};
int N;
ll D;
vi adj[MAX * 2];
namespace subtask2{
bool dp[MAX * 2];
void dfs(int u, int p){
dp[u] = false;
for(auto v : adj[u]) if(v != p){
dfs(v, u);
if(!dp[v]) dp[u] = 1;
}
}
bool check(){
dfs(0, -1);
return dp[0];
}
void solve(){
FOR(i, 0, N){
for(auto j : adj[i]) adj[i+N].pb(j+N);
}
int ans = 0;
FOR(i, 0, N){
FOR(j, 0, N){
adj[i].pb(j+N);
// cout << dbg(i) << dbg(j+N) << '\n';
ans += check();
adj[i].pop_back();
}
}
cout << ans << '\n';
}
}
int main(){
setIO();
cin >> N >> D;
FOR(i, 0, N-1){
int u, v;
cin >> u >> v;
--u, --v;
adj[u].pb(v);
adj[v].pb(u);
}
if(N == 2){
cout << mint(4).power(D) << '\n';
return 0;
}
if(N <= 100 && D == 1){
return subtask2::solve(), 0;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |