Submission #235214

#TimeUsernameProblemLanguageResultExecution timeMemory
235214AtalasionCats or Dogs (JOI18_catdog)C++14
38 / 100
3083 ms9704 KiB
//khodaya khodet komak kon #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #pragma GCC optimize ("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize ("-O2") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const int N = 200000 + 10; const ll MOD = 1000000000 + 7; const ll INF = 1000000010; const ll LOG = 25; int n, dp[N][2], val[N]; vi G[N]; void initialize(int nn, vi A, vi B){ n = nn; for (int i = 0; i <nn - 1; i++){ G[A[i]].pb(B[i]); G[B[i]].pb(A[i]); } } int DFS(int v = 1, int p = 0){ if (val[v] == 1) dp[v][0] = 0, dp[v][1] = INF; else if(val[v] == 2) dp[v][1] = 0, dp[v][0] = INF; else dp[v][0] = dp[v][1] = 0; for (auto u:G[v]){ if (u == p) continue; DFS(u, v); dp[v][0] += min(dp[u][0], dp[u][1] + 1); dp[v][1] += min(dp[u][0] + 1, dp[u][1]); } } int cat(int v){ val[v] = 1; DFS(1, 0); return min(dp[1][0], dp[1][1]); } int dog(int v){ val[v] = 2; DFS(1, 0); return min(dp[1][0], dp[1][1]); } int neighbor(int v){ val[v] = 0; DFS(1, 0); return min(dp[1][0], dp[1][1]); }

Compilation message (stderr)

catdog.cpp: In function 'int DFS(int, int)':
catdog.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...