답안 #421518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421518 2021-06-09T08:38:26 Z 장태환(#7576) Cats or Dogs (JOI18_catdog) C++17
0 / 100
1 ms 332 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);
        }
    }
}
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++)
      |                 ~^~~~~~~~~~~~
catdog.cpp:44:1: warning: no return statement in function returning non-void [-Wreturn-type]
   44 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -