Submission #782545

# Submission time Handle Problem Language Result Execution time Memory
782545 2023-07-14T04:45:08 Z t6twotwo Spring cleaning (CEOI20_cleaning) C++17
34 / 100
1000 ms 13332 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> adj(N);
    for (int i = 0; i < N - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    while (Q--) {
        int D;
        cin >> D;
        for (int i = 0; i < D; i++) {
            int p;
            cin >> p; p--;
            adj.push_back({p});
            adj[p].push_back(N + i);
        }
        int leaves = 0;
        for (int i = 0; i < N + D; i++) {
            leaves += adj[i].size() == 1;
        }
        if (leaves % 2 == 1) {
            cout << -1 << "\n";
        } else {
            int ans = 0;
            auto dfs = [&](auto dfs, int x, int p) -> int {
                int s = adj[x].size() == 1;
                for (int y : adj[x]) {
                    if (y == p) {
                        continue;
                    }
                    int t = dfs(dfs, y, x);
                    ans += 2 - t % 2;
                    s += t;
                }
                return s;
            };
            dfs(dfs, 0, -1);
            cout << ans << "\n";
        }
        adj.resize(N);
        for (int i = 0; i < N; i++) {
            while (adj[i].back() >= N) {
                adj[i].pop_back();
            }
        }
    }
    return 6/22;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1061 ms 1960 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 5260 KB Output is correct
2 Correct 10 ms 5260 KB Output is correct
3 Correct 19 ms 8524 KB Output is correct
4 Correct 33 ms 11556 KB Output is correct
5 Correct 37 ms 11144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 7040 KB Output is correct
2 Correct 12 ms 7092 KB Output is correct
3 Correct 26 ms 9280 KB Output is correct
4 Correct 41 ms 13332 KB Output is correct
5 Correct 24 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 2476 KB Output is correct
2 Correct 105 ms 2260 KB Output is correct
3 Correct 93 ms 2132 KB Output is correct
4 Correct 18 ms 2028 KB Output is correct
5 Correct 164 ms 2004 KB Output is correct
6 Correct 215 ms 2292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 5452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 8148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1061 ms 1960 KB Time limit exceeded
3 Halted 0 ms 0 KB -