Submission #304399

# Submission time Handle Problem Language Result Execution time Memory
304399 2020-09-21T09:26:50 Z BeanZ Spring cleaning (CEOI20_cleaning) C++14
34 / 100
1000 ms 30660 KB
// 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

cleaning.cpp: In function 'int main()':
cleaning.cpp:30:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   30 |                 freopen("test.inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cleaning.cpp:31:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   31 |                 freopen("test.out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9856 KB Output is correct
2 Execution timed out 1052 ms 12536 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 32 ms 15104 KB Output is correct
2 Correct 34 ms 15104 KB Output is correct
3 Correct 61 ms 20200 KB Output is correct
4 Correct 89 ms 22112 KB Output is correct
5 Correct 113 ms 25192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 15928 KB Output is correct
2 Correct 35 ms 15744 KB Output is correct
3 Correct 77 ms 26488 KB Output is correct
4 Correct 116 ms 30660 KB Output is correct
5 Correct 62 ms 24952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 13432 KB Output is correct
2 Correct 225 ms 12284 KB Output is correct
3 Correct 314 ms 11768 KB Output is correct
4 Correct 337 ms 12188 KB Output is correct
5 Correct 361 ms 12416 KB Output is correct
6 Correct 372 ms 12920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 16468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 19884 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9856 KB Output is correct
2 Execution timed out 1052 ms 12536 KB Time limit exceeded