結果

問題 No.1124 Earthquake Safety
ユーザー snukesnuke
提出日時 2020-07-22 23:02:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 393 ms / 3,000 ms
コード長 3,556 bytes
コンパイル時間 3,125 ms
コンパイル使用メモリ 204,160 KB
実行使用メモリ 78,608 KB
最終ジャッジ日時 2023-09-05 03:35:00
合計ジャッジ時間 18,961 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
17,540 KB
testcase_01 AC 9 ms
17,732 KB
testcase_02 AC 9 ms
17,516 KB
testcase_03 AC 9 ms
17,516 KB
testcase_04 AC 8 ms
17,596 KB
testcase_05 AC 9 ms
17,636 KB
testcase_06 AC 9 ms
17,552 KB
testcase_07 AC 15 ms
18,548 KB
testcase_08 AC 100 ms
28,604 KB
testcase_09 AC 355 ms
50,660 KB
testcase_10 AC 200 ms
78,608 KB
testcase_11 AC 8 ms
17,516 KB
testcase_12 AC 8 ms
17,572 KB
testcase_13 AC 8 ms
17,440 KB
testcase_14 AC 381 ms
50,664 KB
testcase_15 AC 383 ms
50,660 KB
testcase_16 AC 388 ms
50,760 KB
testcase_17 AC 376 ms
50,592 KB
testcase_18 AC 385 ms
50,608 KB
testcase_19 AC 380 ms
50,692 KB
testcase_20 AC 387 ms
50,672 KB
testcase_21 AC 393 ms
50,608 KB
testcase_22 AC 377 ms
50,676 KB
testcase_23 AC 341 ms
50,372 KB
testcase_24 AC 343 ms
50,492 KB
testcase_25 AC 332 ms
50,656 KB
testcase_26 AC 329 ms
50,600 KB
testcase_27 AC 329 ms
52,068 KB
testcase_28 AC 333 ms
52,028 KB
testcase_29 AC 354 ms
57,084 KB
testcase_30 AC 350 ms
57,004 KB
testcase_31 AC 367 ms
67,652 KB
testcase_32 AC 362 ms
65,640 KB
testcase_33 AC 361 ms
64,764 KB
testcase_34 AC 363 ms
67,136 KB
testcase_35 AC 339 ms
50,328 KB
testcase_36 AC 323 ms
50,256 KB
testcase_37 AC 326 ms
51,480 KB
testcase_38 AC 325 ms
51,268 KB
testcase_39 AC 329 ms
51,000 KB
testcase_40 AC 329 ms
51,660 KB
testcase_41 AC 320 ms
51,224 KB
testcase_42 AC 318 ms
51,652 KB
testcase_43 AC 318 ms
52,008 KB
testcase_44 AC 316 ms
51,948 KB
testcase_45 AC 317 ms
51,536 KB
testcase_46 AC 318 ms
51,972 KB
testcase_47 AC 314 ms
51,548 KB
testcase_48 AC 309 ms
51,172 KB
testcase_49 AC 313 ms
50,924 KB
testcase_50 AC 8 ms
17,544 KB
testcase_51 AC 8 ms
17,480 KB
testcase_52 AC 8 ms
17,476 KB
testcase_53 AC 9 ms
17,520 KB
testcase_54 AC 8 ms
17,552 KB
testcase_55 AC 9 ms
17,536 KB
testcase_56 AC 9 ms
17,516 KB
testcase_57 AC 8 ms
17,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 300005;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-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 operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
//

vi to[MX];

vm dp[MX];

void dfs(int v, int p=-1) {
  dp[v] = vm(8,1);
  vm& d = dp[v];
  for (int u : to[v]) {
    if (u == p) continue;
    dfs(u,v);
    vm& e = dp[u];
    vm pd(8); swap(d,pd);
    rep(i,8)rep(j,8) {
      if (i&j) continue;
      mint c = 1;
      if (!j || j == 7) c = 2;
      d[i|j] += pd[i]*e[j]*c;
    }
  }
}

int main() {
  int n;
  scanf("%d",&n);
  rep(i,n-1) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  dfs(0);
  mint ans = dp[0][7];
  cout<<ans<<endl;
  return 0;
}




















0