제출 #647912

#제출 시각아이디문제언어결과실행 시간메모리
647912thorieThe Xana coup (BOI21_xanadu)C++17
20 / 100
1099 ms12640 KiB
#include "bits/stdc++.h" using namespace std; vector<vector<int>> graph; vector<bool> on; vector<bool> onCopy; vector<int> v1; vector<int> v2; void toggle(int k) { on[k] = !on[k]; for (int i = 0; i < graph[k].size(); i++) { on[graph[k][i]] = !on[graph[k][i]]; } } void dfs(int x, bool y, int from) { if (y) { v1.push_back(x); } else { v2.push_back(x); } for (int i = 0; i < graph[x].size(); i++) { if (graph[x][i] != from) { dfs(graph[x][i], !y, x); } } } int main() { int n; cin >> n; graph.resize(n); on.resize(n); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; graph[a - 1].push_back(b - 1); graph[b - 1].push_back(a - 1); } for (int i = 0; i < n; i++) { bool a; cin >> a; on[i] = a; } onCopy = on; dfs(0, false, -1); if (v1.size() > v2.size()) { swap(v1, v2); } int m = INT_MAX; for (int i = 0; i < 1 << v1.size(); i++) { int cnt = 0; for (int j = 0; j < v1.size(); j++) { if (i & 1 << j) { toggle(v1[j]); cnt++; } } for (int j = 0; j < v2.size(); j++) { if (on[v2[j]]) { toggle(v2[j]); cnt++; } } bool allFalse = true; for (int j = 0; j < v1.size(); j++) { if (on[v1[j]]) { allFalse = false; break; } } if (allFalse) { m = min(m, cnt); } on = onCopy; } if (m == INT_MAX) { cout << "impossible" << endl; } else { cout << m << endl; } return 0; }

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

xanadu.cpp: In function 'void toggle(int)':
xanadu.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < graph[k].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~
xanadu.cpp: In function 'void dfs(int, bool, int)':
xanadu.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i < graph[x].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~
xanadu.cpp: In function 'int main()':
xanadu.cpp:64:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for (int j = 0; j < v1.size(); j++) {
      |                         ~~^~~~~~~~~~~
xanadu.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for (int j = 0; j < v2.size(); j++) {
      |                         ~~^~~~~~~~~~~
xanadu.cpp:79:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for (int j = 0; j < v1.size(); j++) {
      |                         ~~^~~~~~~~~~~
#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...