Submission #658312

# Submission time Handle Problem Language Result Execution time Memory
658312 2022-11-12T19:25:59 Z Kahou Spring cleaning (CEOI20_cleaning) C++14
34 / 100
1000 ms 13980 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 1e5 + 50;
int n, q, sub[N], ans;
bool om[N], mark[N];
vector<int> adj[N];

void dfs(int u, int p) {
        for (int v:adj[u]) {
                if (v == p) continue;
                dfs(v, u);
                sub[u] += sub[v];
                ans += 1-(sub[v]&1);
        }
}

void solve() {
        cin >> n >> q;
        for (int i = 1; i <= n-1; i++) {
                int u, v;
                cin >> u >> v;
                adj[u].push_back(v);
                adj[v].push_back(u);
        }
        int r = 0;
        for (int u = 1; u <= n; u++) {
                if(adj[u].size() > 1) {
                        if (!r) r = u;
                }
                else {
                        om[u] = 1;
                }
        }
        for (int u = 1; u <= n; u++) {
                mark[u] = om[u];
                sub[u] = om[u];
        }

        while (q--) {
                int d;
                cin >> d;
                for (int i = 1; i <= d; i++) {
                        int u;
                        cin >> u;
                        sub[u]++;
                        if (mark[u]) {
                                sub[u]--;
                                mark[u] = 0;
                        }
                }
                dfs(r, 0);
                cout << (sub[r]&1? -1: n+d-1+ans) << endl;

                for (int u = 1; u <= n; u++) {
                        mark[u] = om[u];
                        sub[u] = om[u];
                }
                ans = 0;
        }
}

int main() {
        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        solve();
        return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Execution timed out 1084 ms 3420 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2772 KB Output is correct
2 Correct 8 ms 2808 KB Output is correct
3 Correct 31 ms 6740 KB Output is correct
4 Correct 24 ms 5452 KB Output is correct
5 Correct 34 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3156 KB Output is correct
2 Correct 9 ms 3248 KB Output is correct
3 Correct 40 ms 13980 KB Output is correct
4 Correct 49 ms 12940 KB Output is correct
5 Correct 50 ms 12976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 4100 KB Output is correct
2 Correct 129 ms 3420 KB Output is correct
3 Correct 171 ms 3588 KB Output is correct
4 Correct 221 ms 4236 KB Output is correct
5 Correct 183 ms 4360 KB Output is correct
6 Correct 229 ms 4400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 5068 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 6432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Execution timed out 1084 ms 3420 KB Time limit exceeded
3 Halted 0 ms 0 KB -