Submission #1054460

#TimeUsernameProblemLanguageResultExecution timeMemory
1054460aymanrsCats or Dogs (JOI18_catdog)C++17
38 / 100
3056 ms6276 KiB
#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+1); 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[1], NULL); return min(g[1].dog, g[1].cat); } int dog(int v) { g[v].state=-1; dfs(&g[1], NULL); return min(g[1].dog, g[1].cat); } int neighbor(int v) { g[v].state=0; dfs(&g[1], NULL); return min(g[1].dog, g[1].cat); }

Compilation message (stderr)

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++){
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...