Submission #963159

# Submission time Handle Problem Language Result Execution time Memory
963159 2024-04-14T15:46:01 Z anton Star Trek (CEOI20_startrek) C++17
23 / 100
53 ms 4584 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long

const int MAX_N = 1001;
const int mod = 1e9+7;


vector<int> adj[MAX_N];
int dpth[MAX_N];
bool can_win[MAX_N][2][MAX_N]; 
bool can_avoid[MAX_N][MAX_N];
bool can_force[MAX_N][MAX_N];

void find_d(int u, int a, int d){
    dpth[u] =d;
    for(auto v: adj[u]){
        if(v!=a){
            find_d(v, u, d+1);
        }
    }
}
void find_win(int f,int pf, int u,int p, int a){
    for(auto v: adj[u]){
        if( v!=a){
            find_win(f, pf, v, (p+1)%2, u);
        }
    }
    
    if(p == 0){
        can_win[f][pf][u] = false;
        for(auto v: adj[u]){
            if( v!=a){
                can_win[f][pf][u] |= can_win[f][pf][v];
            }
        }
    }
    else{
        can_win[f][pf][u] = true;
        for(auto v: adj[u]){
            if(v!=a){
                can_win[f][pf][u] &= can_win[f][pf][v];
            }
        }
    }
}

void avoid(int f, int p, int u, int a){
    int nbc= 0;
    for(auto v: adj[u]){
        if( v!=a){
            avoid(f, (p+1)%2,v, u);
            nbc++;
        }
    }


    
    if(p == 0){
        can_avoid[f][u] = false;
        for(auto v: adj[u]){
            if(v!=a){
                can_avoid[f][u] |= can_avoid[f][v];
            }
        }
    }
    else{
        can_avoid[f][u] = (u!=f);
        for(auto v: adj[u]){
            if(v!=a){
                can_avoid[f][u] &= can_avoid[f][v];
            }
        }
    }

    //cout<<"can avoid "<<f<<" "<<u<<" "<<can_avoid[f][u]<<endl;
}

void force(int f, int p, int u, int a){
    int nbc= 0;
    for(auto v: adj[u]){
        if( v!=a){
            force(f, (p+1)%2,v, u);
            nbc++;
        }
    }


    
    if(p == 1){
        can_force[f][u] = true;
        for(auto v: adj[u]){
            if(v!=a){
                can_force[f][u] &= can_force[f][v];
            }
        }
    }
    else{
        can_force[f][u] = (u==f);
        for(auto v: adj[u]){
            if(v!=a){
                can_force[f][u] |= can_force[f][v];
            }
        }
    }
}


signed main(){
    int n, d;
    cin>>n>>d;
    for(int i = 0; i<n-1;i++){
        int a, b;
        cin>>a>>b;

        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }

    find_d(0, -1, 0);

    for(int i = 0; i<n; i++){
        avoid(i, 0, 0, -1);
    }

    for(int i = 0; i<n; i++){
        find_win(i, 0, i, 0, -1);
        find_win(i, 1, i, 1, -1);
    }
    for(int i = 0; i<n; i++){
        force(i, 0, 0, -1);
    }

    int res= 0;

    vector<int> go(2, 0);

    for(int i = 0; i<n; i++){
        //cout<<i<<" "<<can_win[i][0][i]<<" "<<can_win[i][1][i]<<endl;
        if(can_win[i][0][i]){
            go[0]++;
        }
        if(can_win[i][1][i]){
            go[1]++;
        }
        
    }

    for(int i = 0; i<n; i++){
        if(can_avoid[i][0]){
            //cout<<"full "<<i<<endl;
            res = (res+n)%mod;
        }
        else{
            if((dpth[i]%2 == 0) && can_force[i][0]){
                //cout<<"we lead "<<i<<" "<<go[1]<<endl;
                res= (res + go[1])%mod;
            }
            else if((dpth[i]%2== 1) && can_force[i][0]){
                if(can_win[0][0][i]){
                    //cout<<"no choice but "<<i<<" "<<go[0]<<endl;
                    res =(res +go[0])%mod;
                }
            }
        }
    }
    cout<<res<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Incorrect 37 ms 4192 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 45 ms 4376 KB Output is correct
8 Correct 53 ms 4316 KB Output is correct
9 Correct 36 ms 4584 KB Output is correct
10 Correct 37 ms 4396 KB Output is correct
11 Correct 38 ms 4312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 45 ms 4376 KB Output is correct
8 Correct 53 ms 4316 KB Output is correct
9 Correct 36 ms 4584 KB Output is correct
10 Correct 37 ms 4396 KB Output is correct
11 Correct 38 ms 4312 KB Output is correct
12 Runtime error 1 ms 604 KB Execution killed with signal 11
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 45 ms 4376 KB Output is correct
8 Correct 53 ms 4316 KB Output is correct
9 Correct 36 ms 4584 KB Output is correct
10 Correct 37 ms 4396 KB Output is correct
11 Correct 38 ms 4312 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Incorrect 35 ms 4360 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 45 ms 4376 KB Output is correct
8 Correct 53 ms 4316 KB Output is correct
9 Correct 36 ms 4584 KB Output is correct
10 Correct 37 ms 4396 KB Output is correct
11 Correct 38 ms 4312 KB Output is correct
12 Runtime error 1 ms 604 KB Execution killed with signal 11
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Incorrect 37 ms 4192 KB Output isn't correct
3 Halted 0 ms 0 KB -