답안 #887398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887398 2023-12-14T12:13:42 Z amirhoseinfar1385 Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 5876 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(min(red,blue+1),min(blue,red+1));
    }
    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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 1 ms 2908 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 2908 KB Output is correct
6 Correct 1 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 2908 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 1 ms 2908 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 2908 KB Output is correct
6 Correct 1 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 2908 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 2908 KB Output is correct
18 Correct 22 ms 2908 KB Output is correct
19 Correct 11 ms 3160 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 4 ms 3020 KB Output is correct
22 Correct 5 ms 2908 KB Output is correct
23 Correct 24 ms 2908 KB Output is correct
24 Correct 23 ms 3160 KB Output is correct
25 Correct 12 ms 2908 KB Output is correct
26 Correct 5 ms 2908 KB Output is correct
27 Correct 3 ms 3160 KB Output is correct
28 Correct 6 ms 2908 KB Output is correct
29 Correct 30 ms 3120 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 2908 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 1 ms 2908 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 2908 KB Output is correct
6 Correct 1 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 2908 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 2908 KB Output is correct
18 Correct 22 ms 2908 KB Output is correct
19 Correct 11 ms 3160 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 4 ms 3020 KB Output is correct
22 Correct 5 ms 2908 KB Output is correct
23 Correct 24 ms 2908 KB Output is correct
24 Correct 23 ms 3160 KB Output is correct
25 Correct 12 ms 2908 KB Output is correct
26 Correct 5 ms 2908 KB Output is correct
27 Correct 3 ms 3160 KB Output is correct
28 Correct 6 ms 2908 KB Output is correct
29 Correct 30 ms 3120 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 2908 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Execution timed out 3024 ms 5876 KB Time limit exceeded
34 Halted 0 ms 0 KB -