Submission #539302

# Submission time Handle Problem Language Result Execution time Memory
539302 2022-03-18T16:22:26 Z Lobo Cats or Dogs (JOI18_catdog) C++17
0 / 100
1 ms 340 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] = inf;
    else if(dg[u] == 1) dp[u][0] = inf, 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;
//     }

// }

Compilation message

catdog.cpp: In function 'void dfs(int, int)':
catdog.cpp:24:45: warning: overflow in conversion from 'long long int' to 'int' changes value from '1000000000000000010' to '-1486618614' [-Woverflow]
   24 |     if(ct[u] == 1) dp[u][0] = 0, dp[u][1] = inf;
      |                                             ^~~
catdog.cpp:25:36: warning: overflow in conversion from 'long long int' to 'int' changes value from '1000000000000000010' to '-1486618614' [-Woverflow]
   25 |     else if(dg[u] == 1) dp[u][0] = inf, dp[u][1] = 0;
      |                                    ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -