Submission #421530

# Submission time Handle Problem Language Result Execution time Memory
421530 2021-06-09T08:45:42 Z 장태환(#7576) Cats or Dogs (JOI18_catdog) C++17
38 / 100
38 ms 4280 KB
#include "catdog.h"
#include <vector>
using namespace std;
int dp[1010][2];
vector<int>x[1010];
int sta[1010];
void initialize(int N, std::vector<int> A, std::vector<int> B)
{
    int i;
    for(i=0;i<N-1;i++)
    {
        x[A[i]].push_back(B[i]);
        x[B[i]].push_back(A[i]);
    }
}
int dfs(int n,int par)
{
    dp[n][0]=dp[n][1]=1<<30;
    int i;
    for(i=0;i<x[n].size();i++)
    {
        if(x[n][i]!=par)
            dfs(x[n][i],n);
    }
    if(sta[n]!=1)
    {
        dp[n][0]=0;
        for(i=0;i<x[n].size();i++)
        {
            if(x[n][i]!=par)
                dp[n][0]+=min(dp[x[n][i]][0],dp[x[n][i]][1]+1);
        }
    }
    if(sta[n]!=2)
    {

        dp[n][1]=0;
        for(i=0;i<x[n].size();i++)
        {
            if(x[n][i]!=par)
                dp[n][1]+=min(dp[x[n][i]][1],dp[x[n][i]][0]+1);
        }
    }
    return min(dp[n][0],dp[n][1]);
}
int cat(int v)
{
    sta[v]=2;
    return dfs(1,0);
}

int dog(int v) {
    sta[v]=1;
    return dfs(1,0);
}

int neighbor(int v) {
  sta[v]=0;
  return dfs(1,0);
}

Compilation message

catdog.cpp: In function 'int dfs(int, int)':
catdog.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(i=0;i<x[n].size();i++)
      |             ~^~~~~~~~~~~~
catdog.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(i=0;i<x[n].size();i++)
      |                 ~^~~~~~~~~~~~
catdog.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(i=0;i<x[n].size();i++)
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 308 KB Output is correct
17 Correct 17 ms 320 KB Output is correct
18 Correct 18 ms 332 KB Output is correct
19 Correct 9 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 23 ms 368 KB Output is correct
24 Correct 17 ms 332 KB Output is correct
25 Correct 7 ms 332 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 5 ms 312 KB Output is correct
29 Correct 25 ms 332 KB Output is correct
30 Correct 3 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 5 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 308 KB Output is correct
17 Correct 17 ms 320 KB Output is correct
18 Correct 18 ms 332 KB Output is correct
19 Correct 9 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 23 ms 368 KB Output is correct
24 Correct 17 ms 332 KB Output is correct
25 Correct 7 ms 332 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 5 ms 312 KB Output is correct
29 Correct 25 ms 332 KB Output is correct
30 Correct 3 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 5 ms 332 KB Output is correct
33 Runtime error 38 ms 4280 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -