Submission #587377

# Submission time Handle Problem Language Result Execution time Memory
587377 2022-07-01T17:59:37 Z MilosMilutinovic Spring cleaning (CEOI20_cleaning) C++14
34 / 100
1000 ms 20572 KB
/**
 *    author:  wxhtzdy
 *    created: 01.07.2022 19:07:12
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, q;
  cin >> n >> q;
  const int MAX = 200000;
  vector<vector<int>> g(MAX);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  while (q--) {
    int d;
    cin >> d;
    vector<int> a(d);      
    for (int i = 0; i < d; i++) {
      cin >> a[i];
      --a[i];
      g[a[i]].push_back(n + i);
    }
    vector<int> cnt(n + d);
    int ans = 0;
    function<void(int, int)> Dfs = [&](int v, int pr) {
      if ((int) g[v].size() <= 1) {
        cnt[v] += 1;
      }
      for (int u : g[v]) {
        if (u != pr) {
          Dfs(u, v);
          cnt[v] += cnt[u];
        }
      }
      if (pr != -1) {
        ans += 2 - (cnt[v] % 2);
      }
    };
    int root = 0;
    for (int i = 0; i < n; i++) {
      if ((int) g[i].size() > 1) {
        root = i;
      }
    }       
    Dfs(root, -1);
    if (cnt[root] % 2 == 0) {
      cout << ans << '\n';
    } else {
      cout << -1 << '\n';
    }
    for (int i = 0; i < d; i++) {
      g[a[i]].pop_back();
    }
  }                                                                  
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Execution timed out 1063 ms 5940 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 6228 KB Output is correct
2 Correct 17 ms 6612 KB Output is correct
3 Correct 26 ms 9660 KB Output is correct
4 Correct 49 ms 9628 KB Output is correct
5 Correct 76 ms 10876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 6868 KB Output is correct
2 Correct 14 ms 7344 KB Output is correct
3 Correct 47 ms 20432 KB Output is correct
4 Correct 69 ms 20572 KB Output is correct
5 Correct 39 ms 18988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 6424 KB Output is correct
2 Correct 176 ms 6100 KB Output is correct
3 Correct 236 ms 5948 KB Output is correct
4 Correct 270 ms 6612 KB Output is correct
5 Correct 243 ms 6612 KB Output is correct
6 Correct 283 ms 7224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 7252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 8544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Execution timed out 1063 ms 5940 KB Time limit exceeded
3 Halted 0 ms 0 KB -