結果

問題 No.1227 I hate ThREE
ユーザー ゆきのんゆきのん
提出日時 2020-09-11 22:41:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,343 bytes
コンパイル時間 1,771 ms
コンパイル使用メモリ 171,412 KB
実行使用メモリ 11,820 KB
最終ジャッジ日時 2023-08-27 15:41:35
合計ジャッジ時間 9,536 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

int n,c;
vector<int> G[1<<10];
vector<vector<LL>> dp(1<<10, vector<LL> (1<<10, -1));

LL dfs(int u,int v,int s){
    if(~dp[u][s]) return dp[u][s];
    LL ret = 1;
    for(auto g:G[u]){
        if(g == v) continue;
        LL tmp = 0;
        if(s + 3 < c) tmp = (tmp + dfs(g, u, s + 3))%mod;
        if(s - 3 >= 0) tmp = (tmp + dfs(g, u, s - 3))%mod;
        ret = (ret * tmp)%mod;
    }
    return dp[u][s] = ret;
}

int main(){
    cin >> n >> c;
    for (int i = 0; i < n-1; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    LL ans = 0;
    for (int i = 0; i < c; i++) {
        ans = (ans + dfs(0, -1, i))%mod;
    }
    cout << ans << endl;
}

0