結果

問題 No.1227 I hate ThREE
ユーザー snow39snow39
提出日時 2020-09-11 22:57:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,410 bytes
コンパイル時間 1,040 ms
コンパイル使用メモリ 96,476 KB
実行使用メモリ 50,644 KB
最終ジャッジ日時 2023-08-27 16:21:29
合計ジャッジ時間 6,134 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 18 ms
49,568 KB
testcase_04 AC 18 ms
49,836 KB
testcase_05 AC 23 ms
48,704 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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+dp[0][3000]*(C-2*2999)%MOD)%MOD;
    cout<<ans<<"\n";
  }

  return 0;
}
0