Submission #887397

# Submission time Handle Problem Language Result Execution time Memory
887397 2023-12-14T12:12:52 Z amirhoseinfar1385 Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 7096 KB
#include "catdog.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
vector<int>adj[maxn];
int val[maxn],n,inf=1e6+5;
void pre(int u,int par=0){
    int j=-1;
    for(int i=0;i<(int)adj[u].size();i++){
        if(adj[u][i]!=par){
            pre(adj[u][i],u);
        }
        else{
            j=i;
        }
    }
    if(j>=0){
        adj[u].erase(adj[u].begin()+j);
    }
    return ;
}

pair<int,int>cal(int u){
    vector<pair<int,int>>ret;
    for(auto x:adj[u]){
        ret.push_back(cal(x));
    }
    int red=0,blue=0;
    for(int i=0;i<(int)ret.size();i++){
        red+=min(ret[i].first,ret[i].second+1);
        blue+=min(ret[i].first+1,ret[i].second);
    }
    if(val[u]==0){
        return make_pair(red,blue);
    }
    else if(val[u]==1){
        return make_pair(red,red+1);
    }
    else{
        return make_pair(blue+1,blue);
    }
}

void initialize(int N, std::vector<int> A, std::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]);
    }
    pre(1);
}

int cat(int v) {
    val[v]=1;
    pair<int,int>res=cal(1);
    return min(res.first,res.second);
}

int dog(int v) {
    val[v]=2;
    pair<int,int>res=cal(1);
    return min(res.first,res.second);
}

int neighbor(int v) {
    val[v]=0;
    pair<int,int>res=cal(1);
    return min(res.first,res.second);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 2 ms 3008 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 3008 KB Output is correct
6 Correct 2 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 1 ms 2988 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 2 ms 3008 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 3008 KB Output is correct
6 Correct 2 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 1 ms 2988 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 17 ms 3060 KB Output is correct
18 Correct 21 ms 2908 KB Output is correct
19 Correct 10 ms 2908 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 4 ms 2908 KB Output is correct
22 Correct 4 ms 2908 KB Output is correct
23 Correct 24 ms 2908 KB Output is correct
24 Correct 19 ms 2908 KB Output is correct
25 Correct 9 ms 2908 KB Output is correct
26 Correct 4 ms 2908 KB Output is correct
27 Correct 3 ms 2908 KB Output is correct
28 Correct 7 ms 2908 KB Output is correct
29 Correct 24 ms 3136 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 3016 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 2 ms 3008 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 3008 KB Output is correct
6 Correct 2 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 1 ms 2988 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 17 ms 3060 KB Output is correct
18 Correct 21 ms 2908 KB Output is correct
19 Correct 10 ms 2908 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 4 ms 2908 KB Output is correct
22 Correct 4 ms 2908 KB Output is correct
23 Correct 24 ms 2908 KB Output is correct
24 Correct 19 ms 2908 KB Output is correct
25 Correct 9 ms 2908 KB Output is correct
26 Correct 4 ms 2908 KB Output is correct
27 Correct 3 ms 2908 KB Output is correct
28 Correct 7 ms 2908 KB Output is correct
29 Correct 24 ms 3136 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 3016 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Execution timed out 3034 ms 7096 KB Time limit exceeded
34 Halted 0 ms 0 KB -