結果
問題 | No.1124 Earthquake Safety |
ユーザー | snuke |
提出日時 | 2020-07-22 23:02:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 412 ms / 3,000 ms |
コード長 | 3,556 bytes |
コンパイル時間 | 2,060 ms |
コンパイル使用メモリ | 205,192 KB |
実行使用メモリ | 73,856 KB |
最終ジャッジ日時 | 2024-06-23 00:18:41 |
合計ジャッジ時間 | 18,784 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
17,664 KB |
testcase_01 | AC | 13 ms
17,664 KB |
testcase_02 | AC | 14 ms
17,664 KB |
testcase_03 | AC | 13 ms
17,664 KB |
testcase_04 | AC | 12 ms
17,536 KB |
testcase_05 | AC | 13 ms
17,664 KB |
testcase_06 | AC | 13 ms
17,792 KB |
testcase_07 | AC | 19 ms
18,816 KB |
testcase_08 | AC | 91 ms
28,672 KB |
testcase_09 | AC | 360 ms
50,816 KB |
testcase_10 | AC | 211 ms
73,856 KB |
testcase_11 | AC | 13 ms
17,664 KB |
testcase_12 | AC | 12 ms
17,664 KB |
testcase_13 | AC | 12 ms
17,792 KB |
testcase_14 | AC | 372 ms
50,816 KB |
testcase_15 | AC | 391 ms
50,816 KB |
testcase_16 | AC | 376 ms
50,816 KB |
testcase_17 | AC | 346 ms
50,688 KB |
testcase_18 | AC | 412 ms
50,816 KB |
testcase_19 | AC | 375 ms
50,944 KB |
testcase_20 | AC | 368 ms
50,816 KB |
testcase_21 | AC | 346 ms
50,688 KB |
testcase_22 | AC | 352 ms
50,688 KB |
testcase_23 | AC | 347 ms
50,560 KB |
testcase_24 | AC | 369 ms
50,560 KB |
testcase_25 | AC | 326 ms
50,688 KB |
testcase_26 | AC | 339 ms
50,816 KB |
testcase_27 | AC | 335 ms
52,096 KB |
testcase_28 | AC | 336 ms
51,840 KB |
testcase_29 | AC | 347 ms
56,064 KB |
testcase_30 | AC | 333 ms
56,064 KB |
testcase_31 | AC | 371 ms
64,768 KB |
testcase_32 | AC | 371 ms
63,232 KB |
testcase_33 | AC | 381 ms
62,592 KB |
testcase_34 | AC | 359 ms
64,512 KB |
testcase_35 | AC | 344 ms
50,432 KB |
testcase_36 | AC | 314 ms
50,560 KB |
testcase_37 | AC | 341 ms
51,584 KB |
testcase_38 | AC | 354 ms
51,456 KB |
testcase_39 | AC | 304 ms
51,200 KB |
testcase_40 | AC | 332 ms
51,840 KB |
testcase_41 | AC | 322 ms
51,328 KB |
testcase_42 | AC | 309 ms
51,840 KB |
testcase_43 | AC | 311 ms
52,224 KB |
testcase_44 | AC | 301 ms
52,096 KB |
testcase_45 | AC | 302 ms
51,712 KB |
testcase_46 | AC | 306 ms
52,096 KB |
testcase_47 | AC | 337 ms
51,712 KB |
testcase_48 | AC | 334 ms
51,456 KB |
testcase_49 | AC | 336 ms
51,388 KB |
testcase_50 | AC | 12 ms
17,536 KB |
testcase_51 | AC | 11 ms
17,664 KB |
testcase_52 | AC | 12 ms
17,536 KB |
testcase_53 | AC | 11 ms
17,664 KB |
testcase_54 | AC | 12 ms
17,664 KB |
testcase_55 | AC | 12 ms
17,664 KB |
testcase_56 | AC | 11 ms
17,664 KB |
testcase_57 | AC | 12 ms
17,664 KB |
ソースコード
#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; }