This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ~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];
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){
catt[v] = dogg[v] = 0;
for(auto u : adj[v]) if(u != par){
dfs(u, v);
catt[v] += catt[u];
dogg[v] += dogg[u];
}
if(a[v] == 1){
dogg[v] = catt[v] + 1;
}
if(a[v] == 2){
catt[v] = dogg[v] + 1;
}
if(a[v] == 0){
catt[v] = min(catt[v], dogg[v] + 1);
dogg[v] = min(dogg[v], catt[v] + 1);
}
return;
}
int output(){
dfs(0, -1);
return min(catt[0], dogg[0]);
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |