結果

問題 No.1227 I hate ThREE
ユーザー snow39snow39
提出日時 2020-09-11 22:59:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 95,916 KB
実行使用メモリ 50,488 KB
最終ジャッジ日時 2023-08-30 14:43:10
合計ジャッジ時間 6,335 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 17 ms
49,532 KB
testcase_04 AC 17 ms
49,800 KB
testcase_05 AC 22 ms
48,496 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 55 ms
19,888 KB
testcase_09 AC 48 ms
17,716 KB
testcase_10 AC 33 ms
15,668 KB
testcase_11 AC 157 ms
48,520 KB
testcase_12 AC 165 ms
50,388 KB
testcase_13 AC 18 ms
9,756 KB
testcase_14 AC 47 ms
17,684 KB
testcase_15 AC 63 ms
21,784 KB
testcase_16 AC 102 ms
32,164 KB
testcase_17 AC 78 ms
26,144 KB
testcase_18 AC 127 ms
38,232 KB
testcase_19 AC 110 ms
34,116 KB
testcase_20 AC 133 ms
40,288 KB
testcase_21 AC 10 ms
7,588 KB
testcase_22 AC 112 ms
34,128 KB
testcase_23 AC 221 ms
49,512 KB
testcase_24 AC 205 ms
50,408 KB
testcase_25 AC 226 ms
50,488 KB
testcase_26 AC 172 ms
48,500 KB
testcase_27 AC 178 ms
49,516 KB
testcase_28 AC 180 ms
50,192 KB
testcase_29 AC 184 ms
50,172 KB
testcase_30 AC 173 ms
48,672 KB
testcase_31 AC 177 ms
48,628 KB
testcase_32 AC 183 ms
49,960 KB
testcase_33 AC 173 ms
48,504 KB
testcase_34 AC 181 ms
49,260 KB
testcase_35 AC 174 ms
48,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

vector<vector<int>> g;

ll dp[1001][6006];
int C;

ll dfs(int now,int d,int par){
  if(dp[now][d]!=-1) return dp[now][d];
  dp[now][d]=1;
  for(auto nex:g[now]) if(nex!=par){
    ll res=0;
    if(d+3<=C&&d+3<=6000) res+=dfs(nex,d+3,now);
    if(d-3>=1) res+=dfs(nex,d-3,now);
    res%=MOD;
    dp[now][d]=dp[now][d]*res%MOD;
  }
  return dp[now][d];
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin>>N>>C;
  g.resize(N);
  rep(i,N-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  for(int i=0;i<N;i++) for(int j=0;j<=6000;j++) dp[i][j]=-1;

  for(int i=1;i<=min(C,6000);i++) dfs(0,i,-1);

  if(C<=6000){
    ll ans=0;
    for(int k=1;k<=C;k++) ans=(ans+dp[0][k])%MOD;
    cout<<ans<<"\n";
  }else{
    ll ans=0;
    for(int k=1;k<3000;k++) ans=(ans+dp[0][k])%MOD;
    ans=ans*2%MOD;
    ans=(ans+dp[0][3000]*(C-2*2999)%MOD)%MOD;
    cout<<ans<<"\n";
  }

  return 0;
}
0