# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
398573 | jlallas384 | The Xana coup (BOI21_xanadu) | C++17 | 124 ms | 25148 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100100;
ll dp[N][2][2],col[N];
vector<int> g[N];
ll f(int v,int p,int c,int flp){
if(dp[v][c][flp] != -1) return dp[v][c][flp];
vector<pair<ll,ll>> a;
for(int u: g[v]) if(u != p){
a.emplace_back(f(u,v,col[u]^flp,0),f(u,v,col[u]^flp^1,1)+1);
}
vector<ll> ndp(2,1e9);
ndp[0] = 0;
for(int i = 0; i < a.size(); i++){
vector<ll> mdp(2,1e9);
mdp[0] = min(ndp[0] + a[i].first,ndp[1] + a[i].second);
mdp[1] = min(ndp[1] + a[i].first,ndp[0] + a[i].second);
ndp = mdp;
}
return dp[v][c][flp] = ndp[c^1];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |