Submission #966370

# Submission time Handle Problem Language Result Execution time Memory
966370 2024-04-19T18:34:28 Z anton Spring cleaning (CEOI20_cleaning) C++17
34 / 100
1000 ms 16620 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define pii pair<int, int>
typedef complex<int> point;
const int MAX_N = 100000;

vector<vector<int>> adj;
int total_cost= 0;

int count_leaves(int u, int a){
    int s= 0;
    for(auto v: adj[u]){
        if(v!=a){
            s+=count_leaves(v, u);
        }
    }
    if(s==0){
        s=1;
    }
    if(s%2==0){
        total_cost += 2;
    }
    else{
        total_cost ++;
    }
    
    //cout<<u+1<<" "<<s<<endl;
    return s;
}
signed main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n, k;
    cin>>n>>k;
    adj.resize(n);
    int node = 0;
    int deg=  0;

    for(int i = 0; i<n-1; i++){
        int a, b;
        cin>>a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
        if(adj[a].size()>deg){
            node =a;
            deg = adj[a].size();
        }
        if(adj[b].size()>deg){
            node =b;
            deg = adj[b].size();
        }
    }

    
    for(int i = 0; i<k; i++){
        int d;
        cin>>d;
        vector<int> parents;
        for(int j = 0; j<d; j++){
            int v;
            cin>>v;
            v--;
            parents.push_back(v);
            adj[parents.back()].push_back(adj.size());
            adj.push_back(vector<int>(1, parents.back()));
        }
        total_cost=  0;
        int total = count_leaves(node, -1);
        if(total%2==1){
            cout<<-1<<endl;
        }
        else{
            cout<<total_cost-2<<endl;
        }
        adj.resize(n);
        for(auto e: parents){
            adj[e].pop_back();
        }
    }
}

Compilation message

cleaning.cpp: In function 'int main()':
cleaning.cpp:47:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   47 |         if(adj[a].size()>deg){
      |            ~~~~~~~~~~~~~^~~~
cleaning.cpp:51:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   51 |         if(adj[b].size()>deg){
      |            ~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Execution timed out 1083 ms 2836 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 6932 KB Output is correct
2 Correct 13 ms 6900 KB Output is correct
3 Correct 20 ms 10704 KB Output is correct
4 Correct 32 ms 14228 KB Output is correct
5 Correct 38 ms 13948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 8676 KB Output is correct
2 Correct 15 ms 9944 KB Output is correct
3 Correct 34 ms 10188 KB Output is correct
4 Correct 56 ms 16620 KB Output is correct
5 Correct 26 ms 10496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 3072 KB Output is correct
2 Correct 100 ms 2424 KB Output is correct
3 Correct 149 ms 2136 KB Output is correct
4 Correct 196 ms 2196 KB Output is correct
5 Correct 146 ms 2412 KB Output is correct
6 Correct 220 ms 2768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 7192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1026 ms 12116 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Execution timed out 1083 ms 2836 KB Time limit exceeded
3 Halted 0 ms 0 KB -