답안 #784437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784437 2023-07-16T06:28:41 Z t6twotwo Spring cleaning (CEOI20_cleaning) C++17
9 / 100
1000 ms 11596 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];
                }
            }
        }
        if ((cnt + D) % 2 == 1) {
            cout << -1 << "\n";
        } else {
            cout << 2 * (N - 1) - cnt + D << "\n";
        }
        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 1712 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 852 KB Output is correct
2 Correct 6 ms 852 KB Output is correct
3 Correct 18 ms 7308 KB Output is correct
4 Correct 20 ms 5580 KB Output is correct
5 Correct 25 ms 7728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 789 ms 1108 KB Output is correct
2 Correct 809 ms 1108 KB Output is correct
3 Execution timed out 1075 ms 11596 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1073 ms 2004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 4860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 7476 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 1712 KB Output isn't correct
3 Halted 0 ms 0 KB -