Submission #421520

# Submission time Handle Problem Language Result Execution time Memory
421520 2021-06-09T08:40:08 Z 장태환(#7576) Cats or Dogs (JOI18_catdog) C++17
0 / 100
0 ms 204 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[i][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[i][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 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -