結果

問題 No.1124 Earthquake Safety
ユーザー optopt
提出日時 2020-07-23 01:24:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 437 ms / 3,000 ms
コード長 1,242 bytes
コンパイル時間 2,765 ms
コンパイル使用メモリ 207,592 KB
実行使用メモリ 66,200 KB
最終ジャッジ日時 2023-09-05 08:15:13
合計ジャッジ時間 21,746 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 107 ms
8,588 KB
testcase_09 AC 399 ms
19,744 KB
testcase_10 AC 285 ms
66,200 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 422 ms
19,736 KB
testcase_15 AC 420 ms
19,704 KB
testcase_16 AC 425 ms
19,716 KB
testcase_17 AC 419 ms
19,672 KB
testcase_18 AC 417 ms
19,816 KB
testcase_19 AC 423 ms
19,788 KB
testcase_20 AC 427 ms
19,704 KB
testcase_21 AC 427 ms
19,800 KB
testcase_22 AC 437 ms
19,864 KB
testcase_23 AC 395 ms
19,436 KB
testcase_24 AC 393 ms
19,404 KB
testcase_25 AC 378 ms
19,724 KB
testcase_26 AC 373 ms
19,836 KB
testcase_27 AC 358 ms
22,244 KB
testcase_28 AC 368 ms
22,396 KB
testcase_29 AC 372 ms
30,580 KB
testcase_30 AC 375 ms
30,564 KB
testcase_31 AC 387 ms
48,284 KB
testcase_32 AC 383 ms
45,012 KB
testcase_33 AC 377 ms
43,432 KB
testcase_34 AC 386 ms
47,464 KB
testcase_35 AC 370 ms
19,492 KB
testcase_36 AC 347 ms
19,596 KB
testcase_37 AC 359 ms
20,524 KB
testcase_38 AC 352 ms
20,428 KB
testcase_39 AC 344 ms
20,008 KB
testcase_40 AC 351 ms
20,868 KB
testcase_41 AC 339 ms
20,200 KB
testcase_42 AC 343 ms
20,768 KB
testcase_43 AC 337 ms
20,996 KB
testcase_44 AC 339 ms
21,132 KB
testcase_45 AC 337 ms
20,532 KB
testcase_46 AC 334 ms
21,156 KB
testcase_47 AC 336 ms
20,600 KB
testcase_48 AC 327 ms
21,012 KB
testcase_49 AC 339 ms
20,796 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 1 ms
4,384 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using V = vector<int>;
using VV = vector<V>;
const int MOD  = int(1e9)+7;


struct mint {
  ll x;
  mint(ll x=0) : x(x%MOD) {}
  mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};
using Vm = vector<mint>;


VV G;

Vm dfs(int k, int u, int p=-1) {
  Vm res = {1, 1, 0, 0};
  for (int v : G[u]) if (v != p) {
    auto q = dfs(k, v, u);
    q[0] *= 2;
    q[k] *= 2;
    for (int i=3; i >= 0; --i) {
      res[i] *= q[0];
      for (int j = 1; j <= i; ++j) res[i] += res[i-j] * q[j];
    }
  }
  return res;
}


int main() {
  int n; cin >> n;
  G.assign(n, V());
  for (int i = 0; i < n-1; ++i) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  auto dp2 = dfs(2, 0);
  auto dp3 = dfs(3, 0);

  mint ans = mint(2).pow(n-1) * n;
  ans += dp2[2] * 6;
  ans += dp3[3] * 6;
  cout << ans.x << '\n';
  return 0;
}

0