Submission #667633

# Submission time Handle Problem Language Result Execution time Memory
667633 2022-12-01T20:24:21 Z mychecksedad Star Trek (CEOI20_startrek) C++17
30 / 100
1000 ms 34444 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;

ll po(ll a, ll b){
    ll res = 1;
    while(b){
        if(b&1) (res *= a) %= MOD;
        (a *= a) %= MOD;
        b >>= 1;
    }
    return res;
}

ll n, d, portal, dp[N], X = 0;
bool is[N];
vector<int> g[N];


void dfs(int v, int p){
    dp[v] = 0;
    if(portal == v){
        dp[v] = X;
    }
    for(int u: g[v]){
        if(u != p){
            dfs(u, v);
            dp[v] = max(dp[v], n - dp[u]);
        }
    }
}

void pre(int v, int p){
    is[v] = 0;
    for(int u: g[v]){
        if(u != p){
            pre(u, v);
            is[v] |= !is[u];
        }
    }
}

void solve(){
    cin >> n >> d;
    for(int i = 0 ; i < n - 1; ++i){
        int u, v; cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    if(n == 2){
        cout << po(4, d); return;
    }
    ll ans = 0;

    portal = -1;
    for(int i = 1; i <= n; ++i){
        pre(i, 0);
        X += 1 - is[i];
    }
    for(int i = 1; i <= n; ++i){
        portal = i;
        dfs(1, 0);    
        // for(int j = 1; j <= n; ++j) cout << dp[j] << '.';
        // cout << '\n';
        (ans += dp[1]) %= MOD;
    }
    cout << ans;
}




int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message

startrek.cpp: In function 'int main()':
startrek.cpp:87:16: warning: unused variable 'aa' [-Wunused-variable]
   87 |     int T = 1, aa;
      |                ^~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Incorrect 35 ms 23848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 14 ms 23776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23760 KB Output is correct
6 Correct 13 ms 23812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23760 KB Output is correct
6 Correct 13 ms 23812 KB Output is correct
7 Correct 44 ms 23900 KB Output is correct
8 Correct 48 ms 23828 KB Output is correct
9 Correct 37 ms 23800 KB Output is correct
10 Correct 40 ms 23816 KB Output is correct
11 Correct 41 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23760 KB Output is correct
6 Correct 13 ms 23812 KB Output is correct
7 Correct 44 ms 23900 KB Output is correct
8 Correct 48 ms 23828 KB Output is correct
9 Correct 37 ms 23800 KB Output is correct
10 Correct 40 ms 23816 KB Output is correct
11 Correct 41 ms 23764 KB Output is correct
12 Execution timed out 1092 ms 34444 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23760 KB Output is correct
6 Correct 13 ms 23812 KB Output is correct
7 Correct 44 ms 23900 KB Output is correct
8 Correct 48 ms 23828 KB Output is correct
9 Correct 37 ms 23800 KB Output is correct
10 Correct 40 ms 23816 KB Output is correct
11 Correct 41 ms 23764 KB Output is correct
12 Correct 16 ms 23820 KB Output is correct
13 Incorrect 37 ms 23864 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23760 KB Output is correct
6 Correct 13 ms 23812 KB Output is correct
7 Correct 44 ms 23900 KB Output is correct
8 Correct 48 ms 23828 KB Output is correct
9 Correct 37 ms 23800 KB Output is correct
10 Correct 40 ms 23816 KB Output is correct
11 Correct 41 ms 23764 KB Output is correct
12 Execution timed out 1092 ms 34444 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Incorrect 35 ms 23848 KB Output isn't correct
3 Halted 0 ms 0 KB -