답안 #887559

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887559 2023-12-14T18:26:44 Z amirhoseinfar1385 Cats or Dogs (JOI18_catdog) C++17
38 / 100
3000 ms 7028 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 ;
}
int res=0;
 
pair<int,int>cal(int u){
    pair<int,int>ret=make_pair(0,0);
    for(auto x:adj[u]){
        pair<int,int>fr=cal(x);
        ret.first+=fr.first;
        ret.second+=fr.second;
    }
    int red=0,blue=0;
    if(val[u]==1){
        res+=ret.second;
        return make_pair(1,0);
    }
    if(val[u]==2){
        res+=ret.first;
        return make_pair(0,1);
    }
    res+=min(ret.first,ret.second);
    if(ret.first==ret.second){
        return make_pair(0,0);
    }
    if(ret.first>ret.second){
        return make_pair(1,0);
    }
    return make_pair(0,1);
}
 
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) {
    res=0;
    val[v]=1;
    cal(1);
    return res;
}
 
int dog(int v){
    res=0;
    val[v]=2;
    cal(1);
    return res;
}
 
int neighbor(int v) {
    res=0;
    val[v]=0;
    cal(1);
    return res;
}

Compilation message

catdog.cpp: In function 'std::pair<int, int> cal(int)':
catdog.cpp:31:9: warning: unused variable 'red' [-Wunused-variable]
   31 |     int red=0,blue=0;
      |         ^~~
catdog.cpp:31:15: warning: unused variable 'blue' [-Wunused-variable]
   31 |     int red=0,blue=0;
      |               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 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 3420 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 2996 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 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 3420 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 2996 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 4 ms 2908 KB Output is correct
18 Correct 5 ms 2908 KB Output is correct
19 Correct 4 ms 3004 KB Output is correct
20 Correct 1 ms 2904 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 2 ms 3008 KB Output is correct
23 Correct 7 ms 3064 KB Output is correct
24 Correct 6 ms 3164 KB Output is correct
25 Correct 3 ms 2908 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 2 ms 3000 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 8 ms 2908 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 1 ms 2908 KB Output is correct
32 Correct 2 ms 3008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 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 3420 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 2996 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 4 ms 2908 KB Output is correct
18 Correct 5 ms 2908 KB Output is correct
19 Correct 4 ms 3004 KB Output is correct
20 Correct 1 ms 2904 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 2 ms 3008 KB Output is correct
23 Correct 7 ms 3064 KB Output is correct
24 Correct 6 ms 3164 KB Output is correct
25 Correct 3 ms 2908 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 2 ms 3000 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 8 ms 2908 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 1 ms 2908 KB Output is correct
32 Correct 2 ms 3008 KB Output is correct
33 Execution timed out 3042 ms 7028 KB Time limit exceeded
34 Halted 0 ms 0 KB -