제출 #1096938

#제출 시각아이디문제언어결과실행 시간메모리
1096938andrei_iorgulescuThe Xana coup (BOI21_xanadu)C++14
100 / 100
109 ms27476 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int inf = 1e9; int n, v[100005]; vector<int> g[100005], f[100005]; bool viz[100005]; int dp[100005][2][2]; void dfs(int nod) { viz[nod] = true; for (auto it : g[nod]) if (!viz[it]) f[nod].push_back(it), dfs(it); } void solve(int nod) { for (auto fiu : f[nod]) solve(fiu); for (int sf = 0; sf < 2; sf++) { for (int cf = 0; cf < 2; cf++) { vector<vector<int>> d(f[nod].size() + 1); for (int i = 0; i < d.size(); i++) d[i].resize(2); d[0][0] = cf; d[0][1] = inf; for (int i = 1; i < d.size(); i++) { int fiu = f[nod][i - 1]; for (int cr = 0; cr < 2; cr++) { d[i][cr] = inf; for (int uu = 0; uu < 2; uu++) d[i][cr] = min(d[i][cr], d[i - 1][cr ^ uu] + dp[fiu][cf][uu]); } } dp[nod][sf][cf] = d[d.size() - 1][sf ^ cf ^ v[nod]]; } } } signed main() { cin >> n; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } for (int i = 1; i <= n; i++) cin >> v[i]; dfs(1); solve(1); int kk = min(dp[1][0][0], dp[1][0][1]); if (kk >= inf) cout << "impossible"; else cout << kk; return 0; }

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

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