Submission #657585

#TimeUsernameProblemLanguageResultExecution timeMemory
657585ktkeremThe Xana coup (BOI21_xanadu)C++17
100 / 100
75 ms21288 KiB
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 998244353; 
const ll ous = 2e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
std::vector<ll> ar;std::vector<ll> adj[ous];
ll n , m;
ll dp[ous][2][2];
void dfs(ll crt , ll prv){
    ll pt[2][2];
    ll ct[2][2];
    for(ll i = 0;2>i;i++){
        for(ll j = 0;2>j;j++){
            dp[crt][i][j] = limit;
            pt[i][j] = limit;
            ct[i][j] = limit;
        }
    }
    dp[crt][0][ar[crt]] = 0;
    dp[crt][1][1 - ar[crt]] = 1;
    for(auto j:adj[crt]){
        if(j != prv){
            dfs(j , crt);
            for(ll i = 0;2>i;i++){
                for(ll j = 0;2>j;j++){
                    pt[i][j] = limit;
                }
            }       
            for(ll fp = 0;2>fp;fp++){
                for(ll sp = 0;2>sp;sp++){
                    for(ll tp = 0;2>tp;tp++){
                        pt[fp][sp ^ tp] = std::min(pt[fp][sp ^ tp] , dp[crt][fp][sp] + dp[j][tp][fp]);
                    }
                }
            }
            for(ll i = 0;2>i;i++){
                for(ll j = 0;2>j;j++){
                    dp[crt][i][j] = pt[i][j];
                }
            }
        }
    }
}
void solve(){
    std::cin >> n;
    for(ll i = 1;n>i;i++){
        ll x , y;std::cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    ar.resize(n+1);
    for(ll i = 1;n>=i;i++){
        std::cin >> ar[i];
    }
    dfs(1 , 0);
    ll ans = std::min(dp[1][0][0] , dp[1][1][0]);
    if(ans >= limit){
        std::cout << "impossible\n";
        return;
    }
    std::cout << ans << "\n";
}
signed main(){
    std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
    ll t=1;
    //std::cin >> t >> n >> m;
    ll o = 1;
    while(t--){ 
        //cout << "Case " << o++ << ":\n";
        solve();
    }
    return 0;
}

Compilation message (stderr)

xanadu.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |                                                                               
xanadu.cpp: In function 'void dfs(ll, ll)':
xanadu.cpp:29:8: warning: variable 'ct' set but not used [-Wunused-but-set-variable]
   29 |     ll ct[2][2];
      |        ^~
xanadu.cpp: In function 'int main()':
xanadu.cpp:85:8: warning: unused variable 'o' [-Wunused-variable]
   85 |     ll o = 1;
      |        ^
#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...