Submission #659565

# Submission time Handle Problem Language Result Execution time Memory
659565 2022-11-18T14:16:08 Z Lobo Star Trek (CEOI20_startrek) C++17
23 / 100
1000 ms 69908 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 5e5+10;
const int mod = 1e9+7;

int n, d, SL, SW, dpw[maxn][2], dpl[maxn][2];
vector<int> g[maxn];

void dfs1(int u, int ant) {
    dpw[u][1] = SW*dpw[u][0] + SL*(dpw[u][0]+dpl[u][0]); dpw[u][1]%= mod;
    dpl[u][1] = SW*dpl[u][0]; dpl[u][1]%= mod;

    int qtl = 0;
    for(auto v : g[u]) if(v != ant) {
        qtl+= dpl[v][0];
        dfs1(v,u);
    }

    for(auto v : g[u]) if(v != ant) {
        qtl-= dpl[v][0];
        if(qtl) {
            dpw[u][1]+= dpw[v][1]+dpl[v][1]; dpw[u][1]%= mod;
            dpl[u][1]+= 0;
        }
        else {
            dpw[u][1]+= dpl[v][1]; dpw[u][1]%= mod;
            dpl[u][1]+= dpw[v][1]; dpl[u][1]%= mod;
        }
        qtl+= dpl[v][0];
    }
}

map<int,int> wp[maxn];
int solwp(int u, int ant) {
    if(wp[u].count(ant)) return wp[u][ant];
    wp[u][ant] = 0;
    for(auto v : g[u]) if(v != ant) {
        if(solwp(v,u) == 0) wp[u][ant] = 1;
    }
    return wp[u][ant];
}

void dfs0(int u, int ant) {
    dpw[u][0] = 0;
    for(auto v : g[u]) if(v != ant) {
        dfs0(v,u);
    }
    for(auto v : g[u]) if(v != ant) {
        if(solwp(v,u) == 0) dpw[u][0] = 1;
    }
    dpl[u][0] = 1-dpw[u][0];
}

void solve() {
    cin >> n >> d;

    for(int i = 1; i <= n-1; i++) {
        int u,v; cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int i = 1; i <= n; i++) {
        if(solwp(i,0) == 1) SW++;
        else SL++;
    }

    dfs0(1,0);
    dfs1(1,0);

    cout << dpw[1][1] << endl;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 35540 KB Output is correct
2 Incorrect 20 ms 35736 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 35476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 35564 KB Output is correct
2 Correct 18 ms 35576 KB Output is correct
3 Correct 19 ms 35472 KB Output is correct
4 Correct 19 ms 35588 KB Output is correct
5 Correct 17 ms 35540 KB Output is correct
6 Correct 17 ms 35492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 35564 KB Output is correct
2 Correct 18 ms 35576 KB Output is correct
3 Correct 19 ms 35472 KB Output is correct
4 Correct 19 ms 35588 KB Output is correct
5 Correct 17 ms 35540 KB Output is correct
6 Correct 17 ms 35492 KB Output is correct
7 Correct 23 ms 35868 KB Output is correct
8 Correct 22 ms 35808 KB Output is correct
9 Correct 26 ms 35752 KB Output is correct
10 Correct 22 ms 35796 KB Output is correct
11 Correct 23 ms 35796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 35564 KB Output is correct
2 Correct 18 ms 35576 KB Output is correct
3 Correct 19 ms 35472 KB Output is correct
4 Correct 19 ms 35588 KB Output is correct
5 Correct 17 ms 35540 KB Output is correct
6 Correct 17 ms 35492 KB Output is correct
7 Correct 23 ms 35868 KB Output is correct
8 Correct 22 ms 35808 KB Output is correct
9 Correct 26 ms 35752 KB Output is correct
10 Correct 22 ms 35796 KB Output is correct
11 Correct 23 ms 35796 KB Output is correct
12 Correct 240 ms 64988 KB Output is correct
13 Correct 213 ms 69908 KB Output is correct
14 Execution timed out 1080 ms 45688 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 35564 KB Output is correct
2 Correct 18 ms 35576 KB Output is correct
3 Correct 19 ms 35472 KB Output is correct
4 Correct 19 ms 35588 KB Output is correct
5 Correct 17 ms 35540 KB Output is correct
6 Correct 17 ms 35492 KB Output is correct
7 Correct 23 ms 35868 KB Output is correct
8 Correct 22 ms 35808 KB Output is correct
9 Correct 26 ms 35752 KB Output is correct
10 Correct 22 ms 35796 KB Output is correct
11 Correct 23 ms 35796 KB Output is correct
12 Correct 17 ms 35540 KB Output is correct
13 Incorrect 19 ms 35716 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 35564 KB Output is correct
2 Correct 18 ms 35576 KB Output is correct
3 Correct 19 ms 35472 KB Output is correct
4 Correct 19 ms 35588 KB Output is correct
5 Correct 17 ms 35540 KB Output is correct
6 Correct 17 ms 35492 KB Output is correct
7 Correct 23 ms 35868 KB Output is correct
8 Correct 22 ms 35808 KB Output is correct
9 Correct 26 ms 35752 KB Output is correct
10 Correct 22 ms 35796 KB Output is correct
11 Correct 23 ms 35796 KB Output is correct
12 Correct 240 ms 64988 KB Output is correct
13 Correct 213 ms 69908 KB Output is correct
14 Execution timed out 1080 ms 45688 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 35540 KB Output is correct
2 Incorrect 20 ms 35736 KB Output isn't correct
3 Halted 0 ms 0 KB -