# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
429588 | mosiashvililuka | The Xana coup (BOI21_xanadu) | C++14 | 109 ms | 18756 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;
int a,b,c,d,e,zx,xc,dp[100009][2][2],f[100009];
vector <int> v[100009];
void dfs(int q, int w){
int qw[2],we[2];
int i,j,ii,jj;
for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
if((*it)==w) continue;
dfs((*it),q);
}
for(i=0; i<2; i++){
for(j=0; j<2; j++){
/*for(ii=0; ii<=1; ii++){
qw[ii]=we[ii]=0;
}*/
qw[0]=0;qw[1]=a+2;
jj=i;
for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
if((*it)==w) continue;
we[0]=min(qw[0]+dp[(*it)][0][jj],qw[1]+dp[(*it)][1][jj]);
we[1]=min(qw[1]+dp[(*it)][0][jj],qw[0]+dp[(*it)][1][jj]);
qw[0]=we[0];qw[1]=we[1];
}
dp[q][i][j]=qw[((f[q]^i)^j)]+i;
}
}
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int i,j,ii,jj;
cin>>a;
for(i=1; i<a; i++){
cin>>c>>d;
v[c].push_back(d);
v[d].push_back(c);
}
for(i=1; i<=a; i++) cin>>f[i];
dfs(1,0);
/*for(ii=1; ii<=a; ii++){
cout<<dp[ii][0][0]<<" "<<dp[ii][0][1]<<" "<<dp[ii][1][0]<<" "<<dp[ii][1][1]<<endl;
}*/
zx=min(dp[1][0][0],dp[1][1][0]);
if(zx>a){
cout<<"impossible";
}else{
cout<<zx;
}
return 0;
}
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... |