Submission #637495

#TimeUsernameProblemLanguageResultExecution timeMemory
637495fatemetmhrCats or Dogs (JOI18_catdog)C++17
38 / 100
3067 ms15168 KiB
// ~Be name khoda~ // #include "catdog.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define fi first #define se second const int maxn = 1e6 + 10; const int maxn5 = 5e5 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const int mod = 1e9 + 7; const ll inf = 1e18; int n, catt[maxn5], dogg[maxn5], a[maxn5]; int st[maxn5], ans = 0; vector <int> adj[maxn5]; void initialize(int N, std::vector<int> A, std::vector<int> B) { n = N; for(int i = 0; i < n - 1; i++){ A[i]--; B[i]--; adj[A[i]].pb(B[i]); adj[B[i]].pb(A[i]); } return; } void dfs(int v, int par){ int cat = 0, dog = 0; for(auto u : adj[v]) if(u != par){ dfs(u, v); if(st[u] == 1) dog++; if(st[u] == 2) cat++; } if(a[v] == 1){ ans += cat; st[v] = 1; } if(a[v] == 2){ ans += dog; st[v] = 2; } if(a[v] == 0){ if(cat < dog){ st[v] = 1; ans += cat; } if(cat > dog){ st[v] = 2; ans += dog; } if(cat == dog){ st[v] = 0; ans += cat; } } //cout << v << ' ' << par << ' ' << cat << ' ' << dog << ' ' << a[v] << ' ' << st[v] << ' ' << ans << endl; return; } int output(){ ans = 0; dfs(0, -1); return ans; } int cat(int v) { v--; a[v] = 1; return output(); } int dog(int v) { v--; a[v] = 2; return output(); } int neighbor(int v) { v--; a[v] = 0; return output(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...