Submission #1054456

#TimeUsernameProblemLanguageResultExecution timeMemory
1054456aymanrsCats or Dogs (JOI18_catdog)C++17
0 / 100
1 ms344 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); 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 (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...