Submission #672790

#TimeUsernameProblemLanguageResultExecution timeMemory
672790vjudge1The Xana coup (BOI21_xanadu)C++11
100 / 100
118 ms32212 KiB
/*#pragma GCC optimize ("O3") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops")*/ #include <bits/stdc++.h> #include <set> #include <map> using namespace std; #define ll long long #define N (ll)((ll)1e5+5) #define M ((ll)998244353) #define fi first #define se second ll n, dp[N][2][2], k; bool on[N]; vector<ll> v[N]; vector<ll> p[N][2]; void dfs(ll s, ll par) { dp[s][0][0] = dp[s][0][1] = dp[s][1][0] = dp[s][1][1] = N; ll a, b; a = b = 0; for (auto x : v[s]) if (x != par) { dfs(x, s); p[s][0].push_back(dp[x][0][1] - dp[x][0][0]); a += dp[x][0][0]; p[s][1].push_back(dp[x][1][1] - dp[x][1][0]); b += dp[x][1][0]; } sort(p[s][0].begin(), p[s][0].end()), sort(p[s][1].begin(), p[s][1].end()); dp[s][on[s]][0] = a; dp[s][on[s] ^ 1][1] = b + 1; for (int i = 0; i < p[s][0].size(); i++) { a += p[s][0][i]; b += p[s][1][i]; dp[s][on[s] ^ (i & 1) ^ 1][0] = min(dp[s][on[s] ^ (i & 1) ^ 1][0], a); dp[s][on[s] ^ (i & 1)][1] = min(dp[s][on[s] ^ (i & 1)][1], b + 1); } } int32_t main() { #define int ll ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ll a, b; cin >> n; for (int i = 1; i < n; i++) cin >> a >> b, v[a].push_back(b), v[b].push_back(a); for (int i = 1; i <= n; i++) cin >> on[i]; dfs(1, 0); if (min(dp[1][0][0], dp[1][0][1]) >= n) cout << "impossible"; else cout << min(dp[1][0][0], dp[1][0][1]); }

Compilation message (stderr)

xanadu.cpp: In function 'void dfs(long long int, long long int)':
xanadu.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for (int i = 0; i < p[s][0].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
#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...