Submission #931733

# Submission time Handle Problem Language Result Execution time Memory
931733 2024-02-22T10:16:02 Z LucaIlie Star Trek (CEOI20_startrek) C++17
8 / 100
1000 ms 4948 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5;
const int MAX_D = 1e5;
const int MOD = 1e9 + 7;
bool canWin[MAX_N + 1];
int countChildrenLosers[MAX_N + 1], add[MAX_N + 1], reach[MAX_N + 1], dp[MAX_D][3];
vector<int> adj[MAX_N + 1];

void dfsGame( int u, int p ) {
    canWin[u] = false;
    countChildrenLosers[u] = 0;
    for ( int v: adj[u] ) {
        if ( v == p )
            continue;
        dfsGame( v, u );
        canWin[u] |= (!canWin[v]);
        countChildrenLosers[u] += (!canWin[v]);
    }
}

void dfsCalcAdd( int u, int p ) {
    if ( p == 0 ) {
        add[u] = (canWin[u] ? -1 : 1);
        reach[u] = u;
    } else {
        if ( canWin[u] ) {
            if ( canWin[p] ) {
                add[u] = -1;
                reach[u] = u;
            } else {
                add[u] = add[p] - 1;
                reach[u] = reach[p];
            }
        } else {
            if ( countChildrenLosers[p] >= 2 ) {
                add[u] = 1;
                reach[u] = u;
            } else {
                add[u] = add[p] + 1;
                reach[u] = reach[p];
            }
        }
    }

    for ( int v: adj[u] ) {
        if ( v == p )
            continue;
        dfsCalcAdd( v, u );
    }
}

int main() {
    int n, d;

    cin >> n >> d;
    for ( int i = 0; i < n - 1; i++ ) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back( v );
        adj[v].push_back( u );
        adj[u + n].push_back( v + n );
        adj[v + n].push_back( u + n );
    }

    int ans = 0;
    for ( int u = 1; u <= n; u++ ) {
        for ( int v = n + 1; v <= 2 * n; v++ ) {
            adj[u].push_back( v );
            adj[v].push_back( u );
            dfsGame( 1, 0 );
            if ( canWin[1] )
                ans++;
            adj[u].pop_back();
            adj[v].pop_back();
        }
    }
    cout << ans;
    /*dfsCalcAdd( 1, 0 );

    int winners = 0;
    for ( int v = 1; v <= n; v++ ) {
        winners += canWin[v];
        //printf( "%d: %d %d %d\n", v, canWin[v], add[v], reach[v] );
    }

    int ans = 0;
    for ( int v = 1; v <= n; v++ ) {
        if ( canWin[1] ) {
            if ( canWin[v] )
                ans = (ans + n) % MOD;
            else {
                ans = (ans + winners) % MOD;
                if ( reach[v] != 1 )
                    ans = (ans + n - winners) % MOD;
            }
        } else {
            if ( !canWin[v] ) {
                if ( reach[v] == 1 )
                    ans = (ans + n - winners) % MOD;
            }
        }
        //printf( "%d\n", ans );
    }

    cout << ans << "\n";*/

    /*dp[0][2] = 0;
    dp[0][1] = 1;
    dp[0][2] = 0;
    for ( int i = 1; i <= d; i++ )*/

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Execution timed out 1072 ms 4700 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 19 ms 4696 KB Output is correct
3 Correct 19 ms 4948 KB Output is correct
4 Correct 13 ms 4740 KB Output is correct
5 Correct 15 ms 4700 KB Output is correct
6 Correct 17 ms 4740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 19 ms 4696 KB Output is correct
3 Correct 19 ms 4948 KB Output is correct
4 Correct 13 ms 4740 KB Output is correct
5 Correct 15 ms 4700 KB Output is correct
6 Correct 17 ms 4740 KB Output is correct
7 Execution timed out 1090 ms 4864 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 19 ms 4696 KB Output is correct
3 Correct 19 ms 4948 KB Output is correct
4 Correct 13 ms 4740 KB Output is correct
5 Correct 15 ms 4700 KB Output is correct
6 Correct 17 ms 4740 KB Output is correct
7 Execution timed out 1090 ms 4864 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 19 ms 4696 KB Output is correct
3 Correct 19 ms 4948 KB Output is correct
4 Correct 13 ms 4740 KB Output is correct
5 Correct 15 ms 4700 KB Output is correct
6 Correct 17 ms 4740 KB Output is correct
7 Execution timed out 1090 ms 4864 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 19 ms 4696 KB Output is correct
3 Correct 19 ms 4948 KB Output is correct
4 Correct 13 ms 4740 KB Output is correct
5 Correct 15 ms 4700 KB Output is correct
6 Correct 17 ms 4740 KB Output is correct
7 Execution timed out 1090 ms 4864 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Execution timed out 1072 ms 4700 KB Time limit exceeded
3 Halted 0 ms 0 KB -