結果

問題 No.1124 Earthquake Safety
ユーザー catuppercatupper
提出日時 2020-07-23 00:12:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 3,000 ms
コード長 1,342 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 86,344 KB
実行使用メモリ 62,764 KB
最終ジャッジ日時 2023-09-05 06:17:23
合計ジャッジ時間 19,145 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,676 KB
testcase_01 AC 5 ms
11,812 KB
testcase_02 AC 5 ms
11,524 KB
testcase_03 AC 5 ms
11,548 KB
testcase_04 AC 6 ms
11,588 KB
testcase_05 AC 5 ms
11,580 KB
testcase_06 AC 6 ms
11,560 KB
testcase_07 AC 13 ms
14,128 KB
testcase_08 AC 114 ms
20,936 KB
testcase_09 AC 386 ms
39,692 KB
testcase_10 AC 278 ms
62,764 KB
testcase_11 AC 5 ms
11,584 KB
testcase_12 AC 5 ms
11,516 KB
testcase_13 AC 6 ms
11,544 KB
testcase_14 AC 418 ms
39,652 KB
testcase_15 AC 417 ms
39,820 KB
testcase_16 AC 419 ms
39,640 KB
testcase_17 AC 420 ms
39,656 KB
testcase_18 AC 412 ms
39,676 KB
testcase_19 AC 422 ms
39,704 KB
testcase_20 AC 420 ms
39,796 KB
testcase_21 AC 409 ms
39,732 KB
testcase_22 AC 417 ms
39,936 KB
testcase_23 AC 373 ms
39,432 KB
testcase_24 AC 377 ms
39,688 KB
testcase_25 AC 362 ms
39,692 KB
testcase_26 AC 362 ms
39,580 KB
testcase_27 AC 355 ms
40,972 KB
testcase_28 AC 357 ms
40,788 KB
testcase_29 AC 372 ms
44,924 KB
testcase_30 AC 372 ms
44,968 KB
testcase_31 AC 386 ms
53,824 KB
testcase_32 AC 388 ms
52,116 KB
testcase_33 AC 395 ms
51,460 KB
testcase_34 AC 393 ms
53,500 KB
testcase_35 AC 362 ms
39,360 KB
testcase_36 AC 351 ms
39,320 KB
testcase_37 AC 354 ms
40,576 KB
testcase_38 AC 350 ms
40,272 KB
testcase_39 AC 348 ms
40,196 KB
testcase_40 AC 347 ms
40,772 KB
testcase_41 AC 346 ms
40,328 KB
testcase_42 AC 343 ms
40,696 KB
testcase_43 AC 340 ms
41,060 KB
testcase_44 AC 340 ms
40,992 KB
testcase_45 AC 338 ms
40,592 KB
testcase_46 AC 335 ms
40,872 KB
testcase_47 AC 334 ms
40,564 KB
testcase_48 AC 329 ms
40,296 KB
testcase_49 AC 341 ms
40,460 KB
testcase_50 AC 5 ms
11,528 KB
testcase_51 AC 6 ms
11,508 KB
testcase_52 AC 5 ms
11,612 KB
testcase_53 AC 5 ms
11,796 KB
testcase_54 AC 5 ms
11,588 KB
testcase_55 AC 5 ms
11,524 KB
testcase_56 AC 5 ms
11,556 KB
testcase_57 AC 5 ms
11,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;


Int dp[330000][8];

vector<int> edge[330000];

void dfs(int x, int last = -1){
    for(int i = 0;i < 8;i++)dp[x][i] = 1;
    for(auto to:edge[x]){
        if(to == last)continue;
        dfs(to, x);
        for(int i = 7;i >= 0;i--){
            Int tmp = 0;
            for(int j = 0;j < 8;j++){
                if((j & i) == j){                    
                    (tmp += dp[x][i-j] * dp[to][j] % MOD) %= MOD;//use
                    if(j == 0)(tmp += dp[x][i] * dp[to][0] % MOD) %= MOD;//cut
                }
            }
            if(i == 7)(tmp += dp[x][0] * dp[to][7] % MOD) %=MOD;//cut
            dp[x][i] = tmp;
        }
    }
}

int main(){
    int n, a, b;
    cin >> n;
    for(int i = 0;i < n-1;i++){
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    dfs(1);
    cout << dp[1][7] << endl;
    
    return 0;
}
0