답안 #784417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784417 2023-07-16T06:09:48 Z t6twotwo Spring cleaning (CEOI20_cleaning) C++17
9 / 100
1000 ms 12884 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<int> deg(N);
    vector<vector<int>> adj(N);
    for (int i = 0; i < N - 1; i++) {
        int x, y;
        cin >> x >> y;
        deg[--x]++;
        deg[--y]++;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int cnt = 0;
    vector<int> v(N), par(N, -1);
    auto dfs = [&](auto dfs, int x) -> void {
        if (deg[x] == 1) {
            v[x] = 1;
        }
        for (int y : adj[x]) {
            if (y == par[x]) {
                continue;
            }
            par[y] = x;
            dfs(dfs, y);
            v[x] ^= v[y];
        }
        cnt += v[x];
    };
    dfs(dfs, 0);
    while (Q--) {
        int D;
        cin >> D;
        vector<int> a(D);
        for (int &p : a) {
            cin >> p;
            p--;
            if (deg[p]++ != 1) {
                int x = p;
                while (x != -1) {
                    cnt += v[x] == 0 ? 1 : -1;
                    v[x] ^= 1;
                    x = par[x];
                }
            }
        }
        cnt += D;
        if (cnt % 2 == 1) {
            cout << -1 << "\n";
        } else {
            cout << 2 * (N - 1 + D) - cnt << "\n";
        }
        cnt -= D;
        for (int p : a) {
            if (--deg[p] != 1) {
                int x = p;
                while (x != -1) {
                    cnt += v[x] == 0 ? 1 : -1;
                    v[x] ^= 1;
                    x = par[x];
                }
            }
        }
    }
    return 6/22;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 19 ms 2320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1204 KB Output is correct
2 Correct 6 ms 1236 KB Output is correct
3 Correct 19 ms 8128 KB Output is correct
4 Correct 20 ms 6596 KB Output is correct
5 Correct 28 ms 8976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 804 ms 1584 KB Output is correct
2 Correct 747 ms 1564 KB Output is correct
3 Execution timed out 1072 ms 12884 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1062 ms 2604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 41 ms 6092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 9400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 19 ms 2320 KB Output isn't correct
3 Halted 0 ms 0 KB -