Submission #363284

#TimeUsernameProblemLanguageResultExecution timeMemory
363284r57shellCats or Dogs (JOI18_catdog)C++14
0 / 100
2 ms2668 KiB
#include "catdog.h" #include <array> using namespace std; const int MAXN = 1e5; static vector<int> E[MAXN+2]; static int pet[MAXN+2]; static int N; void initialize(int N, vector<int> A, vector<int> B) { N = A.size(); for (int i = 0; i < N - 1; ++i) { E[A[i]].push_back(B[i]); E[B[i]].push_back(A[i]); } } typedef array<int, 3> dpt; dpt rec(int x, int p) { /*vector<dpt> dd(v); for (int i = 0; i < E[x].size(); ++i) { int v = E[x][i]; if (v != p) dd[i] = rec(v, p); }*/ dpt res; res[0] = 0; res[1] = 0; res[2] = 0; for (int i = 0; i < E[x].size(); ++i) { int v = E[x][i]; if (v != p) { dpt dp = rec(v, x); res[0] += min(dp[0], min(dp[1], dp[2]) + 1); res[1] += min(dp[1], min(dp[0], dp[2] + 1)); res[2] += min(dp[2], min(dp[0], dp[1] + 1)); res[0] = min(res[0], int(1e8)); res[1] = min(res[1], int(1e8)); res[2] = min(res[2], int(1e8)); } } if (pet[x] == 1) { res[0] = int(1e8); res[2] = int(1e8); } else if (pet[x] == 2) { res[0] = int(1e8); res[1] = int(1e8); } //printf("%d %d (%d %d %d)\n", x, p, res[0], res[1], res[2]); return res; } static int solve() { dpt res = rec(1, -1); int ans = min(res[0], min(res[1], res[2]));; //printf("ans = %d\n", ans); return ans; } int cat(int v) { pet[v] = 1; return solve(); } int dog(int v) { pet[v] = 2; return solve(); } int neighbor(int v) { pet[v] = 0; return solve(); }

Compilation message (stderr)

catdog.cpp: In function 'dpt rec(int, int)':
catdog.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for (int i = 0; i < E[x].size(); ++i)
      |                  ~~^~~~~~~~~~~~~
catdog.cpp: At global scope:
catdog.cpp:10:12: warning: 'N' defined but not used [-Wunused-variable]
   10 | static int N;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...