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;
#define lg long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const lg N = 2e5+5;
vector<lg> adj[N];
lg dp[N][2], col[N];
// lg solve(lg src, lg b, lg par)
// {
// auto&ret = dp[src][b];
// if(~ret) return ret;
// ret = 1e18;
// for(int i = 0; i < (1ll << adj[src].size()); i++)
// {
// lg x = (b^(__builtin_popcount(i)&1));
// for(int j = 0; j < adj[src].size(); j++)
// {
//
// }
// }
// return ret;
// }
//par true -> must
//par false -> must not
int main()
{
lg n;
cin >> n;
for(int i = 1; i < n; i++)
{
lg u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
// lg ans = 1e18;
// for(int i = 1; i <= n; i++)
// {
// memset(dp, -1, sizeof(dp));
// ans = min(ans, dfs(i, 0, -1));
// }
for(int i = 1; i <= n; i++)
{
cin >> col[i];
if(!col[i])
{
dp[i][0] = dp[i-1][0];
dp[i][1] = dp[i-1][1]+1;
}
else{
dp[i][0] = dp[i-1][1]+1;
dp[i][1] = dp[i-1][0];
}
}
cout << dp[n][0] << '\n';
}
# | 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... |