Submission #252897

# Submission time Handle Problem Language Result Execution time Memory
252897 2020-07-26T12:17:30 Z test2 Cats or Dogs (JOI18_catdog) C++14
38 / 100
3000 ms 8296 KB
#include <bits/stdc++.h>
//#include "catdog.h"

using namespace std;

const int N = 1e5 + 7;
int n;

vector<int> adj[N] ; 
int hut[N] ; 
int x;
int dp[N][3] ; 

void initialize(int N, std::vector<int> A, std::vector<int> B)
{
        x = A.size();
        for(int i = 0 ; i < N - 1;i ++){
                adj[A[i]].push_back(B[i]) ;
                adj[B[i]].push_back(A[i]) ; 
        }

        return ; 
}

int dfs(int x ,int p , int c){
        int ret = 0 ;         
        if(dp[x][c] != -1){
                return dp[x][c] ; 
        }
        if(hut[x] && hut[x] != c){
                return dp[x][c] = 1e9 ; 
        }

        for(auto u:adj[x] ){
                if( u == p) 
                        continue ; 
                ret += min(dfs(u , x , c) , dfs(u , x, 3 - c) + 1) ; 
        }
        return dp[x][c] = ret ; 
}

int answer(){
        int ret = 1e9 ; 
        memset(dp , -1 , sizeof dp) ;
        ret = min(ret , dfs(1, 1, 1)) ; 
        memset(dp , -1 , sizeof dp) ; 
        ret = min(ret , dfs(1 , 1, 2)) ;
        return ret;
}

int cat(int v)
{
        hut[v] = 1 ;
        return answer() ;
}

int dog(int v)
{
        hut[v] = 2 ; 
        return answer() ;
}

int neighbor(int v)
{
        memset(dp  , -1 , sizeof dp) ; 
        hut[v] = 0 ; 
        return answer();
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3840 KB Output is correct
2 Correct 5 ms 3840 KB Output is correct
3 Correct 6 ms 3840 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 10 ms 3896 KB Output is correct
6 Correct 11 ms 3840 KB Output is correct
7 Correct 11 ms 3840 KB Output is correct
8 Correct 10 ms 3840 KB Output is correct
9 Correct 10 ms 3840 KB Output is correct
10 Correct 11 ms 3840 KB Output is correct
11 Correct 7 ms 3840 KB Output is correct
12 Correct 2 ms 3840 KB Output is correct
13 Correct 6 ms 3840 KB Output is correct
14 Correct 7 ms 3840 KB Output is correct
15 Correct 7 ms 3840 KB Output is correct
16 Correct 10 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3840 KB Output is correct
2 Correct 5 ms 3840 KB Output is correct
3 Correct 6 ms 3840 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 10 ms 3896 KB Output is correct
6 Correct 11 ms 3840 KB Output is correct
7 Correct 11 ms 3840 KB Output is correct
8 Correct 10 ms 3840 KB Output is correct
9 Correct 10 ms 3840 KB Output is correct
10 Correct 11 ms 3840 KB Output is correct
11 Correct 7 ms 3840 KB Output is correct
12 Correct 2 ms 3840 KB Output is correct
13 Correct 6 ms 3840 KB Output is correct
14 Correct 7 ms 3840 KB Output is correct
15 Correct 7 ms 3840 KB Output is correct
16 Correct 10 ms 3840 KB Output is correct
17 Correct 108 ms 3924 KB Output is correct
18 Correct 97 ms 3840 KB Output is correct
19 Correct 50 ms 3840 KB Output is correct
20 Correct 5 ms 3840 KB Output is correct
21 Correct 37 ms 3912 KB Output is correct
22 Correct 38 ms 3840 KB Output is correct
23 Correct 138 ms 3840 KB Output is correct
24 Correct 122 ms 3960 KB Output is correct
25 Correct 72 ms 3840 KB Output is correct
26 Correct 33 ms 3840 KB Output is correct
27 Correct 35 ms 3968 KB Output is correct
28 Correct 25 ms 3968 KB Output is correct
29 Correct 134 ms 3968 KB Output is correct
30 Correct 52 ms 3840 KB Output is correct
31 Correct 13 ms 3840 KB Output is correct
32 Correct 65 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3840 KB Output is correct
2 Correct 5 ms 3840 KB Output is correct
3 Correct 6 ms 3840 KB Output is correct
4 Correct 11 ms 3840 KB Output is correct
5 Correct 10 ms 3896 KB Output is correct
6 Correct 11 ms 3840 KB Output is correct
7 Correct 11 ms 3840 KB Output is correct
8 Correct 10 ms 3840 KB Output is correct
9 Correct 10 ms 3840 KB Output is correct
10 Correct 11 ms 3840 KB Output is correct
11 Correct 7 ms 3840 KB Output is correct
12 Correct 2 ms 3840 KB Output is correct
13 Correct 6 ms 3840 KB Output is correct
14 Correct 7 ms 3840 KB Output is correct
15 Correct 7 ms 3840 KB Output is correct
16 Correct 10 ms 3840 KB Output is correct
17 Correct 108 ms 3924 KB Output is correct
18 Correct 97 ms 3840 KB Output is correct
19 Correct 50 ms 3840 KB Output is correct
20 Correct 5 ms 3840 KB Output is correct
21 Correct 37 ms 3912 KB Output is correct
22 Correct 38 ms 3840 KB Output is correct
23 Correct 138 ms 3840 KB Output is correct
24 Correct 122 ms 3960 KB Output is correct
25 Correct 72 ms 3840 KB Output is correct
26 Correct 33 ms 3840 KB Output is correct
27 Correct 35 ms 3968 KB Output is correct
28 Correct 25 ms 3968 KB Output is correct
29 Correct 134 ms 3968 KB Output is correct
30 Correct 52 ms 3840 KB Output is correct
31 Correct 13 ms 3840 KB Output is correct
32 Correct 65 ms 3840 KB Output is correct
33 Execution timed out 3066 ms 8296 KB Time limit exceeded
34 Halted 0 ms 0 KB -