# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
304399 | BeanZ | Spring cleaning (CEOI20_cleaning) | C++14 | 1093 ms | 30660 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e5 + 5;
vector<ll> adj[N];
vector<ll> node[N];
ll dp[N], sz[N];
void dfs(ll u, ll p){
dp[u] = 0;
sz[u] = 0;
for (auto j : adj[u]){
if (j == p) continue;
dfs(j, u);
dp[u] += dp[j];
sz[u] += sz[j];
dp[u] += sz[j];
}
if (adj[u].size() == 1) sz[u]++;
sz[u] = sz[u] & 1;
if (sz[u] == 0) sz[u] = 2;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n, m;
cin >> n >> m;
for (int i = 1; i < n; i++){
ll u, v;
cin >> u >> v;
node[u].push_back(v);
node[v].push_back(u);
}
for (int i = 1; i <= m; i++){
ll d;
cin >> d;
for (int j = 1; j <= (n + d); j++){
adj[j] = node[j];
}
for (int j = (n + 1); j <= (n + d); j++){
ll u;
cin >> u;
adj[u].push_back(j);
adj[j].push_back(u);
}
dfs(1, 1);
if (sz[1] == 2) cout << dp[1] << endl;
else cout << -1 << endl;
}
}
/*
7 3
1 2
2 4
4 5
5 6
5 7
3 4
1 4
2 2 4
1 1
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |