Submission #786093

# Submission time Handle Problem Language Result Execution time Memory
786093 2023-07-18T03:13:04 Z Charizard2021 Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 6280 KB
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include"catdog.h"
using namespace std;
const int N = 100001;
int n;
vector<int> adj[N];
int dp[N][3];
int val[N];
void dfs(int u, int p){
    dp[u][1] = 0;
    dp[u][2] = 0;
    for(int v : adj[u]){
        if(v != p){
            dfs(v, u);
            dp[u][1] += min(dp[v][0], dp[v][1]);
            dp[u][2] += min(dp[v][0], dp[v][2]);
        }
    }
    if(val[u] == 1){
        dp[u][2] = 1e9;
    }
    if(val[u] == 2){
        dp[u][1] = 1e9;
    }
    dp[u][0] = min(dp[u][1], dp[u][2]) + 1;
}
int solve(){
    dfs(1, 0);
    return dp[1][0] - 1;
}
void initialize(int N, vector<int> a, vector<int> b){
    n = N;
    for(int i = 0; i < N - 1; i++){
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }
}
int cat(int u){
    val[u] = 1;
    return solve();
}
int dog(int u){
    val[u] = 2;
    return solve();
}
int neighbor(int u){
    val[u] = 0;
    return solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 7 ms 2704 KB Output is correct
18 Correct 9 ms 2644 KB Output is correct
19 Correct 5 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 10 ms 2644 KB Output is correct
24 Correct 8 ms 2644 KB Output is correct
25 Correct 6 ms 2644 KB Output is correct
26 Correct 3 ms 2644 KB Output is correct
27 Correct 2 ms 2680 KB Output is correct
28 Correct 4 ms 2752 KB Output is correct
29 Correct 13 ms 2772 KB Output is correct
30 Correct 3 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 3 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 7 ms 2704 KB Output is correct
18 Correct 9 ms 2644 KB Output is correct
19 Correct 5 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 10 ms 2644 KB Output is correct
24 Correct 8 ms 2644 KB Output is correct
25 Correct 6 ms 2644 KB Output is correct
26 Correct 3 ms 2644 KB Output is correct
27 Correct 2 ms 2680 KB Output is correct
28 Correct 4 ms 2752 KB Output is correct
29 Correct 13 ms 2772 KB Output is correct
30 Correct 3 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 3 ms 2644 KB Output is correct
33 Execution timed out 3049 ms 6280 KB Time limit exceeded
34 Halted 0 ms 0 KB -