結果

問題 No.1124 Earthquake Safety
ユーザー milanis48663220milanis48663220
提出日時 2023-09-20 00:51:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 3,000 ms
コード長 2,264 bytes
コンパイル時間 1,406 ms
コンパイル使用メモリ 122,896 KB
実行使用メモリ 52,584 KB
最終ジャッジ日時 2023-09-20 00:51:25
合計ジャッジ時間 13,656 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
15,076 KB
testcase_01 AC 7 ms
15,088 KB
testcase_02 AC 7 ms
15,044 KB
testcase_03 AC 7 ms
15,072 KB
testcase_04 AC 7 ms
15,080 KB
testcase_05 AC 7 ms
15,204 KB
testcase_06 AC 7 ms
15,124 KB
testcase_07 AC 10 ms
15,400 KB
testcase_08 AC 70 ms
18,284 KB
testcase_09 AC 254 ms
25,068 KB
testcase_10 AC 120 ms
52,584 KB
testcase_11 AC 6 ms
15,200 KB
testcase_12 AC 6 ms
15,132 KB
testcase_13 AC 7 ms
15,136 KB
testcase_14 AC 263 ms
24,816 KB
testcase_15 AC 251 ms
24,812 KB
testcase_16 AC 251 ms
24,788 KB
testcase_17 AC 272 ms
24,988 KB
testcase_18 AC 248 ms
24,832 KB
testcase_19 AC 249 ms
24,936 KB
testcase_20 AC 247 ms
24,792 KB
testcase_21 AC 258 ms
24,752 KB
testcase_22 AC 251 ms
24,776 KB
testcase_23 AC 217 ms
24,628 KB
testcase_24 AC 216 ms
24,564 KB
testcase_25 AC 206 ms
24,692 KB
testcase_26 AC 210 ms
24,768 KB
testcase_27 AC 201 ms
26,328 KB
testcase_28 AC 204 ms
26,172 KB
testcase_29 AC 214 ms
31,148 KB
testcase_30 AC 211 ms
31,152 KB
testcase_31 AC 226 ms
41,892 KB
testcase_32 AC 229 ms
39,820 KB
testcase_33 AC 221 ms
39,040 KB
testcase_34 AC 218 ms
41,476 KB
testcase_35 AC 211 ms
24,512 KB
testcase_36 AC 208 ms
24,532 KB
testcase_37 AC 206 ms
25,696 KB
testcase_38 AC 201 ms
25,472 KB
testcase_39 AC 195 ms
25,144 KB
testcase_40 AC 198 ms
25,920 KB
testcase_41 AC 193 ms
25,424 KB
testcase_42 AC 219 ms
26,028 KB
testcase_43 AC 192 ms
26,132 KB
testcase_44 AC 189 ms
26,124 KB
testcase_45 AC 187 ms
25,812 KB
testcase_46 AC 192 ms
26,088 KB
testcase_47 AC 189 ms
25,716 KB
testcase_48 AC 184 ms
25,412 KB
testcase_49 AC 190 ms
25,388 KB
testcase_50 AC 7 ms
15,132 KB
testcase_51 AC 7 ms
15,136 KB
testcase_52 AC 7 ms
15,152 KB
testcase_53 AC 7 ms
15,068 KB
testcase_54 AC 7 ms
15,068 KB
testcase_55 AC 7 ms
15,040 KB
testcase_56 AC 7 ms
15,080 KB
testcase_57 AC 7 ms
15,100 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;
}

const mint inv2 = mint(2).inv();
const mint inv6 = mint(6).inv();

vector<int> g[300005];
mint dp[300005][4];

void dfs(int v, int par){
    dp[v][0] = 1;
    dp[v][1] = 1;
    dp[v][2] = inv2;
    dp[v][3] = inv6;
    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; c0+c1 <= 3; c1++){
                nx[c0+c1] += dp[v][c0]*dp[to][c1];
            }
        }
        for(int c = 0; c <= 3; c++) dp[v][c] = nx[c];
    }
    dp[v][1] *= inv2;
    dp[v][2] *= inv2;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> 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);
    }
    dfs(0, -1);
    mint ans = (dp[0][3]*6)*mint(2).pow(n-1);
    cout << ans << endl;
}
0