結果

問題 No.1227 I hate ThREE
ユーザー snow39snow39
提出日時 2020-09-11 22:54:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,297 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 95,948 KB
実行使用メモリ 50,652 KB
最終ジャッジ日時 2023-08-27 16:03:52
合計ジャッジ時間 4,491 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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){
  dp[now][d]=1;
  for(auto nex:g[now]) if(nex!=par){
    ll res=0;
    if(d+3<=C) 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=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