제출 #122625

#제출 시각아이디문제언어결과실행 시간메모리
122625WhipppedCreamCats or Dogs (JOI18_catdog)C++17
38 / 100
3064 ms7236 KiB
#include "catdog.h" #include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC target ("sse4") using namespace std; #define X first #define Y second #define pb push_back typedef pair<int, int> ii; typedef long long ll; const int maxn = 1e5+5; vector<int> adj[maxn]; int dp[3][maxn]; int st[maxn]; int n; void compute(int u = 1, int p = 0) { dp[1][u] = dp[2][u] = 0; for(int v : adj[u]) { if(v == p) continue; compute(v, u); dp[1][u] += min(dp[1][v], 1+dp[2][v]); dp[2][u] += min(dp[2][v], 1+dp[1][v]); } if(st[u] == 1) dp[2][u] = 1e9; if(st[u] == 2) dp[1][u] = 1e9; } void initialize(int N, vector<int> A, vector<int> B) { n = N; for(int i = 0; i< n-1; i++) { adj[A[i]].pb(B[i]); adj[B[i]].pb(A[i]); } } int cat(int u) { st[u] = 1; compute(); return min(dp[1][1], dp[2][1]); } int dog(int u) { st[u] = 2; compute(); return min(dp[1][1], dp[2][1]); } int neighbor(int u) { st[u] = 0; compute(); return min(dp[1][1], dp[2][1]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...