Submission #539303

# Submission time Handle Problem Language Result Execution time Memory
539303 2022-03-18T16:22:50 Z Lobo Cats or Dogs (JOI18_catdog) C++17
38 / 100
27 ms 4284 KB
#include "catdog.h"
#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()

#define maxn 1010

int n, dp[maxn][3], ct[maxn], dg[maxn];
vector<int> g[maxn];

void dfs(int u, int ant) {
    //dp(u,0) = u é C
    //dp(u,1) = u é D
    if(ct[u] == 1) dp[u][0] = 0, dp[u][1] = inf1;
    else if(dg[u] == 1) dp[u][0] = inf1, dp[u][1] = 0;
    else dp[u][0] = 0, dp[u][1] = 0;
    for(auto v : g[u]) {
        if(v == ant) continue;
        dfs(v,u);
        dp[u][0]+= min(dp[v][0],1+dp[v][1]);
        dp[u][1]+= min(dp[v][1],1+dp[v][0]);
    }
}

int cat(int v) {
    ct[v] = 1;
    dfs(1,1);
    return min(dp[1][0],dp[1][1]);
}

int dog(int v) {
    dg[v] = 1;
    dfs(1,1);
    return min(dp[1][0],dp[1][1]);
}

int neighbor(int v) {
    ct[v] = 0;
    dg[v] = 0;
    dfs(1,1);
    return min(dp[1][0],dp[1][1]);
}

void initialize(int N, vector<int> A, vector<int> B) {
    n = N;
    for(int i = 0; i < n-1; i++) {
        g[A[i]].pb(B[i]);
        g[B[i]].pb(A[i]);
    }
}

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

//     freopen("in.in", "r", stdin);
//     // freopen("out.out", "w", stdout);

//     int N; cin >> N;
//     int A[N-1], B[N-1];
//     for(int i = 0; i < N-1; i++) {
//         cin >> A[i] >> B[i];
//     }
//     Initialize(N,A,B);
//     int Q; cin >> Q;
//     while(Q--) {
//         int op,v;
//         cin >> op >> v;
//         if(op == 1) cout << cat(v) << endl;
//         if(op == 2) cout << dog(v) << endl;
//         if(op == 3) cout << neighbor(v) << endl;
//     }

// }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 360 KB Output is correct
17 Correct 10 ms 388 KB Output is correct
18 Correct 12 ms 340 KB Output is correct
19 Correct 8 ms 468 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 17 ms 336 KB Output is correct
24 Correct 12 ms 456 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 328 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 15 ms 332 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 360 KB Output is correct
17 Correct 10 ms 388 KB Output is correct
18 Correct 12 ms 340 KB Output is correct
19 Correct 8 ms 468 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 17 ms 336 KB Output is correct
24 Correct 12 ms 456 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 328 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 15 ms 332 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Runtime error 27 ms 4284 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -