結果

問題 No.1124 Earthquake Safety
ユーザー milanis48663220milanis48663220
提出日時 2023-09-20 00:47:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 440 ms / 3,000 ms
コード長 2,359 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 128,992 KB
実行使用メモリ 82,608 KB
最終ジャッジ日時 2023-09-20 00:48:03
合計ジャッジ時間 24,063 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 11 ms
4,384 KB
testcase_08 AC 120 ms
14,048 KB
testcase_09 AC 371 ms
36,220 KB
testcase_10 AC 308 ms
82,608 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 393 ms
36,152 KB
testcase_15 AC 376 ms
36,244 KB
testcase_16 AC 382 ms
36,292 KB
testcase_17 AC 424 ms
36,240 KB
testcase_18 AC 381 ms
36,252 KB
testcase_19 AC 376 ms
36,240 KB
testcase_20 AC 401 ms
36,448 KB
testcase_21 AC 375 ms
36,220 KB
testcase_22 AC 387 ms
36,252 KB
testcase_23 AC 399 ms
36,028 KB
testcase_24 AC 371 ms
35,896 KB
testcase_25 AC 365 ms
36,152 KB
testcase_26 AC 388 ms
36,224 KB
testcase_27 AC 360 ms
38,596 KB
testcase_28 AC 364 ms
38,512 KB
testcase_29 AC 411 ms
47,140 KB
testcase_30 AC 382 ms
47,116 KB
testcase_31 AC 418 ms
64,772 KB
testcase_32 AC 440 ms
61,624 KB
testcase_33 AC 428 ms
59,908 KB
testcase_34 AC 423 ms
63,888 KB
testcase_35 AC 386 ms
36,036 KB
testcase_36 AC 356 ms
35,776 KB
testcase_37 AC 358 ms
36,972 KB
testcase_38 AC 378 ms
36,712 KB
testcase_39 AC 344 ms
36,512 KB
testcase_40 AC 342 ms
37,236 KB
testcase_41 AC 339 ms
36,752 KB
testcase_42 AC 343 ms
37,188 KB
testcase_43 AC 341 ms
37,536 KB
testcase_44 AC 344 ms
37,500 KB
testcase_45 AC 365 ms
36,968 KB
testcase_46 AC 340 ms
37,488 KB
testcase_47 AC 347 ms
36,976 KB
testcase_48 AC 359 ms
37,092 KB
testcase_49 AC 331 ms
36,888 KB
testcase_50 AC 1 ms
4,384 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 2 ms
4,384 KB
testcase_53 AC 1 ms
4,384 KB
testcase_54 AC 1 ms
4,380 KB
testcase_55 AC 2 ms
4,384 KB
testcase_56 AC 1 ms
4,384 KB
testcase_57 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint1000000007;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0; i < n-1; i++){
        int a, b; cin >> a >> b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto dp = vec2d(n, 4, mint(0));
    function<void(int, int)> dfs = [&](int v, int par){
        dp[v][0] = 1;
        dp[v][1] = 1;
        dp[v][2] = mint(2).inv();
        dp[v][3] = mint(6).inv();
        for(int to: g[v]){
            if(to == par) continue;
            dfs(to, v);
            vector<mint> nx(4);
            for(int c0 = 0; c0 <= 3; c0++){
                for(int c1 = 0; c1 <= 3; c1++){
                    if(c0+c1 <= 3){
                        nx[c0+c1] += dp[v][c0]*dp[to][c1];
                    }
                }
            }
            dp[v] = nx;
        }
        dp[v][1] /= 2;
        dp[v][2] /= 2;
    };
    dfs(0, -1);
    mint ans = (dp[0][3]*6)*mint(2).pow(n-1);
    cout << ans << endl;
}
0