답안 #1054456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054456 2024-08-12T10:01:42 Z aymanrs Cats or Dogs (JOI18_catdog) C++17
0 / 100
1 ms 344 KB
#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;
struct node {
  vector<node*> l;
  int dog, cat;
  char state = 0; // -1 dog 1 cat
};
vector<node> g;
void initialize(int N, std::vector<int> A, std::vector<int> B) {
  g.resize(N);
  for(int i = 0;i < A.size();i++){
    g[A[i]].l.push_back(&g[B[i]]);
    g[B[i]].l.push_back(&g[A[i]]);
  }
}
void dfs(node* n, node* p){
  n->dog = n->cat = 0;
  if(n->state==1) n->dog = 1e7;
  else if(n->state==-1) n->cat = 1e7;
  for(node* c : n->l){
    if(c==p) continue;
    dfs(c,n);
    n->dog += min(c->dog, c->cat+1);
    n->cat += min(c->cat, c->dog+1);
  }
}
int cat(int v) {
  g[v].state=1;
  dfs(&g[0], NULL);
  return min(g[0].dog, g[0].cat);
}

int dog(int v) {
  g[v].state=-1;
  dfs(&g[0], NULL);
  return min(g[0].dog, g[0].cat);
}

int neighbor(int v) {
  g[v].state=0;
  dfs(&g[0], NULL);
  return min(g[0].dog, g[0].cat);
}

Compilation message

catdog.cpp: In function 'void initialize(int, std::vector<int>, std::vector<int>)':
catdog.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for(int i = 0;i < A.size();i++){
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -