답안 #477538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477538 2021-10-02T13:42:24 Z nicolaalexandra Cats or Dogs (JOI18_catdog) C++14
38 / 100
3000 ms 6852 KB
#include <bits/stdc++.h>
#include "catdog.h"
#define DIM 100010
#define INF 2000000000
using namespace std;

vector <int> L[DIM],a,b;
int v[DIM],dp[DIM][3];
int n,i,q,tip,x;


void initialize(int _n, vector<int> A, vector<int> B) {
    n = _n;
    for (int i=0;i<n-1;i++){
        L[A[i]].push_back(B[i]);
        L[B[i]].push_back(A[i]);
    }
}

void dfs (int nod, int tata){

    for (auto vecin : L[nod])
        if (vecin != tata)
            dfs (vecin,nod);

    if (!v[nod])
        dp[nod][1] = dp[nod][2] = 0;
    else {
        if (v[nod] == 1)
            dp[nod][1] = 0, dp[nod][2] = INF;
        else
            dp[nod][1] = INF, dp[nod][2] = 0;
    }

    for (auto vecin : L[nod]){
        if (vecin == tata)
            continue;
        dp[nod][1] += min (dp[vecin][1],dp[vecin][2]+1);
        dp[nod][2] += min (dp[vecin][2],dp[vecin][1]+1);
    }

}


int cat(int x) {
    v[x] = 1;

    memset (dp,0,sizeof dp);

    dfs (1,0);

    return min(dp[1][1],dp[1][2]);
}

int dog(int x) {
    v[x] = 2;

    memset (dp,0,sizeof dp);

    dfs (1,0);

    return min(dp[1][1],dp[1][2]);
}

int neighbor(int x) {
    v[x] = 0;

    memset (dp,0,sizeof dp);

    dfs (1,0);

    return min(dp[1][1],dp[1][2]);
}

/*
int main (){

    ifstream cin ("date.in");
    ofstream cout ("date.out");


    cin>>n;
    for (i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        a.push_back(x);
        b.push_back(y);
        //cin>>a[i]>>b[i];
    }

    initialize(n,a,b);

    cin>>q;
    for (;q--;){
        cin>>tip>>x;
        if (tip == 1)
            cout<<cat(x)<<"\n";
        else {
            if (tip == 2)
                cout<<dog(x)<<"\n";
            else cout<<neighbor(x)<<"\n";
        }
    }



    return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3788 KB Output is correct
2 Correct 3 ms 3788 KB Output is correct
3 Correct 3 ms 3788 KB Output is correct
4 Correct 6 ms 3788 KB Output is correct
5 Correct 6 ms 3788 KB Output is correct
6 Correct 6 ms 3788 KB Output is correct
7 Correct 5 ms 3788 KB Output is correct
8 Correct 5 ms 3788 KB Output is correct
9 Correct 6 ms 3828 KB Output is correct
10 Correct 5 ms 3788 KB Output is correct
11 Correct 4 ms 3788 KB Output is correct
12 Correct 2 ms 3788 KB Output is correct
13 Correct 3 ms 3788 KB Output is correct
14 Correct 4 ms 3792 KB Output is correct
15 Correct 4 ms 3788 KB Output is correct
16 Correct 5 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3788 KB Output is correct
2 Correct 3 ms 3788 KB Output is correct
3 Correct 3 ms 3788 KB Output is correct
4 Correct 6 ms 3788 KB Output is correct
5 Correct 6 ms 3788 KB Output is correct
6 Correct 6 ms 3788 KB Output is correct
7 Correct 5 ms 3788 KB Output is correct
8 Correct 5 ms 3788 KB Output is correct
9 Correct 6 ms 3828 KB Output is correct
10 Correct 5 ms 3788 KB Output is correct
11 Correct 4 ms 3788 KB Output is correct
12 Correct 2 ms 3788 KB Output is correct
13 Correct 3 ms 3788 KB Output is correct
14 Correct 4 ms 3792 KB Output is correct
15 Correct 4 ms 3788 KB Output is correct
16 Correct 5 ms 3788 KB Output is correct
17 Correct 40 ms 3788 KB Output is correct
18 Correct 39 ms 3864 KB Output is correct
19 Correct 30 ms 3788 KB Output is correct
20 Correct 3 ms 3788 KB Output is correct
21 Correct 17 ms 3812 KB Output is correct
22 Correct 22 ms 3832 KB Output is correct
23 Correct 56 ms 3788 KB Output is correct
24 Correct 50 ms 3788 KB Output is correct
25 Correct 38 ms 3788 KB Output is correct
26 Correct 13 ms 3840 KB Output is correct
27 Correct 15 ms 3836 KB Output is correct
28 Correct 11 ms 3896 KB Output is correct
29 Correct 59 ms 3888 KB Output is correct
30 Correct 26 ms 3788 KB Output is correct
31 Correct 6 ms 3788 KB Output is correct
32 Correct 26 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3788 KB Output is correct
2 Correct 3 ms 3788 KB Output is correct
3 Correct 3 ms 3788 KB Output is correct
4 Correct 6 ms 3788 KB Output is correct
5 Correct 6 ms 3788 KB Output is correct
6 Correct 6 ms 3788 KB Output is correct
7 Correct 5 ms 3788 KB Output is correct
8 Correct 5 ms 3788 KB Output is correct
9 Correct 6 ms 3828 KB Output is correct
10 Correct 5 ms 3788 KB Output is correct
11 Correct 4 ms 3788 KB Output is correct
12 Correct 2 ms 3788 KB Output is correct
13 Correct 3 ms 3788 KB Output is correct
14 Correct 4 ms 3792 KB Output is correct
15 Correct 4 ms 3788 KB Output is correct
16 Correct 5 ms 3788 KB Output is correct
17 Correct 40 ms 3788 KB Output is correct
18 Correct 39 ms 3864 KB Output is correct
19 Correct 30 ms 3788 KB Output is correct
20 Correct 3 ms 3788 KB Output is correct
21 Correct 17 ms 3812 KB Output is correct
22 Correct 22 ms 3832 KB Output is correct
23 Correct 56 ms 3788 KB Output is correct
24 Correct 50 ms 3788 KB Output is correct
25 Correct 38 ms 3788 KB Output is correct
26 Correct 13 ms 3840 KB Output is correct
27 Correct 15 ms 3836 KB Output is correct
28 Correct 11 ms 3896 KB Output is correct
29 Correct 59 ms 3888 KB Output is correct
30 Correct 26 ms 3788 KB Output is correct
31 Correct 6 ms 3788 KB Output is correct
32 Correct 26 ms 3788 KB Output is correct
33 Execution timed out 3072 ms 6852 KB Time limit exceeded
34 Halted 0 ms 0 KB -