Submission #1045488

#TimeUsernameProblemLanguageResultExecution timeMemory
1045488pccThe Xana coup (BOI21_xanadu)C++17
70 / 100
45 ms27988 KiB
#include <bits/stdc++.h> using namespace std; int N; const int mxn = 1e5+10; int dp[mxn][2][2]; vector<int> tree[mxn]; int arr[mxn]; void dfs(int now,int par){ for(int i = 0;i<2;i++)for(int j = 0;j<2;j++)dp[now][i][j] = mxn; vector<int> v0,v1; int s0 = 0,s1 = 0; for(auto nxt:tree[now]){ if(nxt == par)continue; dfs(nxt,now); s0 += dp[nxt][0][0]; s1 += dp[nxt][1][0]; v0.push_back(dp[nxt][0][1]-dp[nxt][0][0]); v1.push_back(dp[nxt][1][1]-dp[nxt][1][0]); } sort(v0.begin(),v0.end()); sort(v1.begin(),v1.end()); int t = arr[now]; int ts = s0; dp[now][t][0] = ts; for(int i = 1;i<v0.size();i+=2){ ts += v0[i-1]+v0[i]; dp[now][t][0] = min(dp[now][t][0],ts); } ts = s1; for(int i = 0;i<v1.size();i+=2){ if(i)ts += v1[i-1]+v1[i]; else ts += v1[i]; dp[now][t][1] = min(dp[now][t][1],ts+1); } t ^= 1; ts = s0; for(int i = 0;i<v0.size();i+=2){ if(i)ts += v0[i-1]+v0[i]; else ts += v0[i]; dp[now][t][0] = min(dp[now][t][0],ts); } ts = s1; dp[now][t][1] = ts+1; for(int i = 1;i<v1.size();i+=2){ ts += v1[i]+v1[i-1]; dp[now][t][1] = min(dp[now][t][1],ts+1); } return; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N; for(int i = 1;i<N;i++){ int a,b; cin>>a>>b; tree[a].push_back(b); tree[b].push_back(a); } for(int i = 1;i<=N;i++)cin>>arr[i]; dfs(1,1); int ans = min(dp[1][0][0],dp[1][0][1]); if(ans>N)cout<<"impossible\n"; else cout<<ans<<'\n'; return 0; }

Compilation message (stderr)

xanadu.cpp: In function 'void dfs(int, int)':
xanadu.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for(int i = 1;i<v0.size();i+=2){
      |                ~^~~~~~~~~~
xanadu.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for(int i = 0;i<v1.size();i+=2){
      |                ~^~~~~~~~~~
xanadu.cpp:42:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for(int i = 0;i<v0.size();i+=2){
      |                ~^~~~~~~~~~
xanadu.cpp:49:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for(int i = 1;i<v1.size();i+=2){
      |                ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...