답안 #914453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914453 2024-01-22T07:40:45 Z manizare Cats or Dogs (JOI18_catdog) C++17
컴파일 오류
0 ms 0 KB
#include "catdog.h"
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
using namespace std ;   
const int maxn = 1e6 + 10 , inf= 2e9 , mod = 1e9 + 7 , sq = 360 ,MX = 20000 ;
int dp[maxn][2] , mark[maxn]; 
vector <int> G[maxn] ;

void dfs(int v, int p =0 ){
    dp[v][0] = dp[v][1]= 0;
    if(mark[v]==1)dp[v][1] = inf ;
    if(mark[v]==2)dp[v][0] = inf ;
    for(int u : G[v]){
        if(u == p)continue ;
        dfs(u , v);
        dp[v][0]= dp[v][0] + min(dp[u][1] + 1 , dp[u][0]) ;
        dp[v][1]= dp[v][1] + min(dp[u][0] + 1 , dp[u][1]) ;
    }
}

void initialize(int N , vector <int> a , vector <int> b){
    rep(i , 0 , N-2){
        G[a[i]+1].pb(b[i]+1) ;
        G[b[i]+1].pb(a[i]+1) ;
    }
}
int cat(int v){
    mark[v]=1;
    dfs(1);
    return min(dp[v][0] , dp[v][1]) ;
}
int dog(int v){
    mark[v]=2;
    dfs(1) ;
    return min(dp[1][0] , dp[1][1]) ;
}
void neighbor(int v){
    mark[v] = 0 ;
    dfs(1) ;
    return min(dp[1][0] , dp[1][1]) ;
}

Compilation message

catdog.cpp:47:6: error: ambiguating new declaration of 'void neighbor(int)'
   47 | void neighbor(int v){
      |      ^~~~~~~~
In file included from catdog.cpp:1:
catdog.h:8:5: note: old declaration 'int neighbor(int)'
    8 | int neighbor(int v);
      |     ^~~~~~~~
catdog.cpp: In function 'void neighbor(int)':
catdog.cpp:50:15: error: return-statement with a value, in function returning 'void' [-fpermissive]
   50 |     return min(dp[1][0] , dp[1][1]) ;
      |            ~~~^~~~~~~~~~~~~~~~~~~~~