結果
| 問題 |
No.1124 Earthquake Safety
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-23 00:12:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 424 ms / 3,000 ms |
| コード長 | 1,342 bytes |
| コンパイル時間 | 861 ms |
| コンパイル使用メモリ | 92,448 KB |
| 実行使用メモリ | 62,760 KB |
| 最終ジャッジ日時 | 2024-06-23 02:39:45 |
| 合計ジャッジ時間 | 18,280 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 58 |
ソースコード
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;
Int dp[330000][8];
vector<int> edge[330000];
void dfs(int x, int last = -1){
for(int i = 0;i < 8;i++)dp[x][i] = 1;
for(auto to:edge[x]){
if(to == last)continue;
dfs(to, x);
for(int i = 7;i >= 0;i--){
Int tmp = 0;
for(int j = 0;j < 8;j++){
if((j & i) == j){
(tmp += dp[x][i-j] * dp[to][j] % MOD) %= MOD;//use
if(j == 0)(tmp += dp[x][i] * dp[to][0] % MOD) %= MOD;//cut
}
}
if(i == 7)(tmp += dp[x][0] * dp[to][7] % MOD) %=MOD;//cut
dp[x][i] = tmp;
}
}
}
int main(){
int n, a, b;
cin >> n;
for(int i = 0;i < n-1;i++){
cin >> a >> b;
edge[a].push_back(b);
edge[b].push_back(a);
}
dfs(1);
cout << dp[1][7] << endl;
return 0;
}