답안 #871583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871583 2023-11-11T06:56:00 Z Trisanu_Das Star Trek (CEOI20_startrek) C++17
45 / 100
45 ms 19664 KB
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int N=1e5+5;
const ll mod=1e9+7;
 
ll binpow(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1)res*=a,res%=mod;
        a*=a,a%=mod;
        b>>=1;
    }
    return res;
}
 
int n;
ll d,ans,sum;
vector<int> adj[N];
ll dp[N][4];
bool dp1[N],dp2[N];
 
void dfs(int u,int p){
    for(auto v:adj[u]){
        if(v==p)continue;
        dfs(v,u);
        dp1[u]|=!dp1[v];
    }
}
 
void dfs2(int u,int p,bool w){
    int cnt=!w;
    dp2[u]=dp1[u]|!w;
    for(auto v:adj[u]){
        if(v==p)continue;
        cnt+=!dp1[v];
    }
    for(auto v:adj[u]){
        if(v==p)continue;
        dfs2(v,u,cnt-!dp1[v]>0);
    }
}
 
void dfs3(int u,int p){
    int cnt=0;
    for(auto v:adj[u]){
        if(v==p)continue;
        cnt+=!dp1[v];
    }
    for(auto v:adj[u]){
        if(v==p)continue;
        dfs3(v,u);
        dp[u][0]+=dp[v][1];
        if(cnt-!dp1[v]>0)dp[u][0]+=dp[v][0];
        else dp[u][1]+=dp[v][0];
        dp[u][0]%=mod;
        dp[u][1]%=mod;
    }
    dp[u][0]+=n-sum;
    if(dp1[u])dp[u][0]+=sum;
    else dp[u][1]+=sum;
    dp[u][0]%=mod;
    dp[u][1]%=mod;
}
 
int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> d;
    if(n==2)cout << binpow(4,d),exit(0);
    for(int i=1;i<n;i++){
        int u,v;
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }
    dfs(1,1);
    dfs2(1,1,true);
    for(int i=1;i<=n;i++)sum+=dp2[i];
    dfs3(1,1);
    cout << dp[1][0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Incorrect 2 ms 3932 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Correct 1 ms 3676 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 1 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 2 ms 3676 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 1 ms 3676 KB Output is correct
6 Correct 1 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 2 ms 3676 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 1 ms 3676 KB Output is correct
6 Correct 1 ms 3676 KB Output is correct
7 Correct 1 ms 3932 KB Output is correct
8 Correct 1 ms 3932 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 1 ms 3932 KB Output is correct
11 Correct 1 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 2 ms 3676 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 1 ms 3676 KB Output is correct
6 Correct 1 ms 3676 KB Output is correct
7 Correct 1 ms 3932 KB Output is correct
8 Correct 1 ms 3932 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 1 ms 3932 KB Output is correct
11 Correct 1 ms 3932 KB Output is correct
12 Correct 43 ms 13396 KB Output is correct
13 Correct 45 ms 19664 KB Output is correct
14 Correct 32 ms 10712 KB Output is correct
15 Correct 35 ms 10332 KB Output is correct
16 Correct 34 ms 10248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 2 ms 3676 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 1 ms 3676 KB Output is correct
6 Correct 1 ms 3676 KB Output is correct
7 Correct 1 ms 3932 KB Output is correct
8 Correct 1 ms 3932 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 1 ms 3932 KB Output is correct
11 Correct 1 ms 3932 KB Output is correct
12 Correct 1 ms 3676 KB Output is correct
13 Incorrect 1 ms 3932 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 2 ms 3676 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 1 ms 3676 KB Output is correct
6 Correct 1 ms 3676 KB Output is correct
7 Correct 1 ms 3932 KB Output is correct
8 Correct 1 ms 3932 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 1 ms 3932 KB Output is correct
11 Correct 1 ms 3932 KB Output is correct
12 Correct 43 ms 13396 KB Output is correct
13 Correct 45 ms 19664 KB Output is correct
14 Correct 32 ms 10712 KB Output is correct
15 Correct 35 ms 10332 KB Output is correct
16 Correct 34 ms 10248 KB Output is correct
17 Correct 1 ms 3676 KB Output is correct
18 Incorrect 1 ms 3932 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Incorrect 2 ms 3932 KB Output isn't correct
3 Halted 0 ms 0 KB -