Submission #914459

# Submission time Handle Problem Language Result Execution time Memory
914459 2024-01-22T07:49:40 Z manizare Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 31168 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
using namespace std ;   
const int maxn = 1e6 + 10 , inf= 2e9 , mod = 1e9 + 7 , sq = 360 ,MX = 20000 ;
int dp[maxn][2] , mark[maxn]; 
vector <int> G[maxn] ;

void dfs(int v, int p =0 ){
    dp[v][0] = dp[v][1]= 0;
    if(mark[v]==1)dp[v][1] = inf ;
    if(mark[v]==2)dp[v][0] = inf ;
    for(int u : G[v]){
        if(u == p)continue ;
        dfs(u , v);
        dp[v][0]= dp[v][0] + min(dp[u][1] + 1 , dp[u][0]) ;
        dp[v][1]= dp[v][1] + min(dp[u][0] + 1 , dp[u][1]) ;
    }
}

void initialize(int N , vector <int> a , vector <int> b){
    rep(i , 0 , N-2){
        G[a[i]].pb(b[i]) ;
        G[b[i]].pb(a[i]) ;
    }
}
int cat(int v){
    mark[v]=1;
    dfs(1);
    return min(dp[1][0] , dp[1][1]) ;
}
int dog(int v){
    mark[v]=2;
    dfs(1) ;
    return min(dp[1][0] , dp[1][1]) ;
}
int neighbor(int v){
    mark[v] = 0 ;
    dfs(1) ;
    return min(dp[1][0] , dp[1][1]) ;
}
/*
signed main(){
    int n ;
    cin >> n ;
    rep(i , 1, n-1){
        int v,u;
        cin >> v >> u ;
        G[v].pb(u);
        G[u].pb(v) ;
    }
    int t ;
    cin >> t;
     while(t--){
        int x , v; 
        cin >> x >> v ;
        if(x==1){
            cout << dog(v) << "\n" ;
        }else {
            cout << cat(v) << "\n" ;
        }
     }
}
*/
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27228 KB Output is correct
2 Correct 9 ms 27280 KB Output is correct
3 Correct 9 ms 27228 KB Output is correct
4 Correct 8 ms 27228 KB Output is correct
5 Correct 9 ms 27288 KB Output is correct
6 Correct 8 ms 27284 KB Output is correct
7 Correct 8 ms 27228 KB Output is correct
8 Correct 8 ms 27224 KB Output is correct
9 Correct 8 ms 27228 KB Output is correct
10 Correct 8 ms 27228 KB Output is correct
11 Correct 8 ms 27248 KB Output is correct
12 Correct 7 ms 27252 KB Output is correct
13 Correct 8 ms 27228 KB Output is correct
14 Correct 8 ms 27224 KB Output is correct
15 Correct 8 ms 27288 KB Output is correct
16 Correct 7 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27228 KB Output is correct
2 Correct 9 ms 27280 KB Output is correct
3 Correct 9 ms 27228 KB Output is correct
4 Correct 8 ms 27228 KB Output is correct
5 Correct 9 ms 27288 KB Output is correct
6 Correct 8 ms 27284 KB Output is correct
7 Correct 8 ms 27228 KB Output is correct
8 Correct 8 ms 27224 KB Output is correct
9 Correct 8 ms 27228 KB Output is correct
10 Correct 8 ms 27228 KB Output is correct
11 Correct 8 ms 27248 KB Output is correct
12 Correct 7 ms 27252 KB Output is correct
13 Correct 8 ms 27228 KB Output is correct
14 Correct 8 ms 27224 KB Output is correct
15 Correct 8 ms 27288 KB Output is correct
16 Correct 7 ms 27228 KB Output is correct
17 Correct 13 ms 27224 KB Output is correct
18 Correct 14 ms 27228 KB Output is correct
19 Correct 11 ms 27228 KB Output is correct
20 Correct 8 ms 27228 KB Output is correct
21 Correct 10 ms 27224 KB Output is correct
22 Correct 9 ms 27228 KB Output is correct
23 Correct 15 ms 27228 KB Output is correct
24 Correct 15 ms 27228 KB Output is correct
25 Correct 12 ms 27484 KB Output is correct
26 Correct 9 ms 27228 KB Output is correct
27 Correct 8 ms 27228 KB Output is correct
28 Correct 10 ms 27264 KB Output is correct
29 Correct 17 ms 27228 KB Output is correct
30 Correct 9 ms 27264 KB Output is correct
31 Correct 9 ms 27228 KB Output is correct
32 Correct 10 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27228 KB Output is correct
2 Correct 9 ms 27280 KB Output is correct
3 Correct 9 ms 27228 KB Output is correct
4 Correct 8 ms 27228 KB Output is correct
5 Correct 9 ms 27288 KB Output is correct
6 Correct 8 ms 27284 KB Output is correct
7 Correct 8 ms 27228 KB Output is correct
8 Correct 8 ms 27224 KB Output is correct
9 Correct 8 ms 27228 KB Output is correct
10 Correct 8 ms 27228 KB Output is correct
11 Correct 8 ms 27248 KB Output is correct
12 Correct 7 ms 27252 KB Output is correct
13 Correct 8 ms 27228 KB Output is correct
14 Correct 8 ms 27224 KB Output is correct
15 Correct 8 ms 27288 KB Output is correct
16 Correct 7 ms 27228 KB Output is correct
17 Correct 13 ms 27224 KB Output is correct
18 Correct 14 ms 27228 KB Output is correct
19 Correct 11 ms 27228 KB Output is correct
20 Correct 8 ms 27228 KB Output is correct
21 Correct 10 ms 27224 KB Output is correct
22 Correct 9 ms 27228 KB Output is correct
23 Correct 15 ms 27228 KB Output is correct
24 Correct 15 ms 27228 KB Output is correct
25 Correct 12 ms 27484 KB Output is correct
26 Correct 9 ms 27228 KB Output is correct
27 Correct 8 ms 27228 KB Output is correct
28 Correct 10 ms 27264 KB Output is correct
29 Correct 17 ms 27228 KB Output is correct
30 Correct 9 ms 27264 KB Output is correct
31 Correct 9 ms 27228 KB Output is correct
32 Correct 10 ms 27228 KB Output is correct
33 Execution timed out 3101 ms 31168 KB Time limit exceeded
34 Halted 0 ms 0 KB -