結果
| 問題 |
No.1227 I hate ThREE
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2020-09-11 23:08:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,247 bytes |
| コンパイル時間 | 2,277 ms |
| コンパイル使用メモリ | 209,424 KB |
| 最終ジャッジ日時 | 2025-01-14 11:30:17 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 TLE * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const char newl = '\n';
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
vector<T> ts(n);
for(size_t i=0;i<n;i++) cin>>ts[i];
return ts;
}
template<typename T,T MOD = 1000000007>
struct Mint{
static constexpr T mod = MOD;
T v;
Mint():v(0){}
Mint(signed v):v(v){}
Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}
Mint pow(long long k){
Mint res(1),tmp(v);
while(k){
if(k&1) res*=tmp;
tmp*=tmp;
k>>=1;
}
return res;
}
static Mint add_identity(){return Mint(0);}
static Mint mul_identity(){return Mint(1);}
Mint inv(){return pow(MOD-2);}
Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
Mint& operator/=(Mint a){return (*this)*=a.inv();}
Mint operator+(Mint a) const{return Mint(v)+=a;}
Mint operator-(Mint a) const{return Mint(v)-=a;}
Mint operator*(Mint a) const{return Mint(v)*=a;}
Mint operator/(Mint a) const{return Mint(v)/=a;}
Mint operator-() const{return v?Mint(MOD-v):Mint(v);}
bool operator==(const Mint a)const{return v==a.v;}
bool operator!=(const Mint a)const{return v!=a.v;}
bool operator <(const Mint a)const{return v <a.v;}
static Mint comb(long long n,int k){
Mint num(1),dom(1);
for(int i=0;i<k;i++){
num*=Mint(n-i);
dom*=Mint(i+1);
}
return num/dom;
}
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
template<typename F>
struct FixPoint : F{
FixPoint(F&& f):F(forward<F>(f)){}
template<typename... Args>
decltype(auto) operator()(Args&&... args) const{
return F::operator()(*this,forward<Args>(args)...);
}
};
template<typename F>
inline decltype(auto) MFP(F&& f){
return FixPoint<F>{forward<F>(f)};
}
//INSERT ABOVE HERE
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n,c;
cin>>n>>c;
vector<vector<int>> G(n);
for(int i=1;i<n;i++){
int a,b;
cin>>a>>b;
a--;b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
using P = pair<short, short>;
using M = Mint<int>;
vector<map<P, M>> dp(n);
MFP([&](auto dfs,int v,int p)->void{
map<P, M> res;
res[P(0,0)]=M(1);
for(int u:G[v]){
if(u==p) continue;
dfs(u,v);
map<P, M> nxt;
for(auto p:res){
for(auto q:dp[u]){
nxt[P(min<int>(p.first.first,q.first.first-1),
max<int>(p.first.second,q.first.second-1))]+=p.second*q.second;
nxt[P(min<int>(p.first.first,q.first.first+1),
max<int>(p.first.second,q.first.second+1))]+=p.second*q.second;
}
}
swap(res,nxt);
}
dp[v]=res;
})(0,-1);
M ans{0};
for(auto p:dp[0]){
auto [l,r]=p.first;
if((r-l)*3>=c) continue;
ans+=M(c-(r-l)*3)*p.second;
}
cout<<ans<<newl;
return 0;
}
beet