제출 #427230

#제출 시각아이디문제언어결과실행 시간메모리
427230keko37The Xana coup (BOI21_xanadu)C++14
100 / 100
149 ms24340 KiB
#include<bits/stdc++.h> using namespace std; typedef long long llint; typedef pair <int, int> pi; const int MAXN = 100005; int n; llint dp[MAXN][2][2], par[MAXN], col[MAXN]; vector <int> v[MAXN]; void dfs (int x, int rod) { par[x] = rod; for (auto sus : v[x]) { if (sus != rod) dfs(sus, x); } } llint calc (int x, int f, int p) { if (dp[x][f][p] != -1) return dp[x][f][p]; llint res = 1e9; llint sum = 0, br = 0, mn = 1e9; for (auto sus : v[x]) { if (sus == par[x]) continue; llint a = calc(sus, 0, f); llint b = calc(sus, 1, f); sum += min(a, b); if (b <= a) br ^= 1; mn = min(mn, abs(a - b)); } if (br != f ^ p ^ col[x]) res = sum + mn; else res = sum; res += f; return dp[x][f][p] = res; } int main () { ios_base::sync_with_stdio(false); cin.tie(0); memset(dp, -1, sizeof dp); cin >> n; for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } for (int i = 1; i <= n; i++) { cin >> col[i]; } dfs(1, 0); llint sol = min(calc(1, 0, 0), calc(1, 1, 0)); if (sol >= 1e9) cout << "impossible"; else cout << sol; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

xanadu.cpp: In function 'llint calc(int, int, int)':
xanadu.cpp:33:12: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   33 |     if (br != f ^ p ^ col[x]) res = sum + mn; else res = sum;
      |         ~~~^~~~
#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...