답안 #558063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558063 2022-05-06T16:31:27 Z status_coding Spring cleaning (CEOI20_cleaning) C++14
34 / 100
1000 ms 15416 KB
#include <bits/stdc++.h>

using namespace std;

int n,q,sz,root;
int cntEven;

int nrLeaf[100005];
int aux[100005];

vector<int> v[100005];

vector<int> upd;

void dfs(int p, int par)
{
    nrLeaf[p] = 0;

    for(int it : v[p])
    {
        if(it == par)
            continue;

        dfs(it, p);
        nrLeaf[p] += nrLeaf[it];
    }

    nrLeaf[p] += aux[p];

    if(!nrLeaf[p])
        nrLeaf[p] = 1;

    if(nrLeaf[p] % 2 == 0)
        cntEven++;
}

void solveBig(int k, vector<int> &upd)
{
    for(int it : upd)
        aux[it] ++;

    cntEven=0;
    dfs(root, 0);

    if(nrLeaf[root] % 2)
        cout<<"-1\n";
    else
        cout<<n+k-1 + cntEven-1<<'\n';

    for(int i=1;i<=n;i++)
        aux[i] = 0;

    cntEven=0;
    dfs(root, 0);
}

void solveSmall(int k, vector<int> &upd)
{
    cout<<"mic\n";
}

int main()
{
    cin>>n>>q;
    //sz = sqrt((int)1e5);
    sz=0;

    for(int i=1;i<n;i++)
    {
        int x, y;
        cin>>x>>y;

        v[x].push_back(y);
        v[y].push_back(x);
    }

    for(int i=1;i<=n;i++)
        if((int)v[i].size() >= 2)
            root = i;

    cntEven=0;
    dfs(root, 0);

    while(q)
    {
        q--;

        upd.clear();

        int k;
        cin>>k;

        for(int i=1;i<=k;i++)
        {
            int x;
            cin>>x;

            upd.push_back(x);
        }

        if(k >= sz)
            solveBig(k, upd);
        else
            solveSmall(k, upd);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Execution timed out 1092 ms 3976 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3772 KB Output is correct
2 Correct 25 ms 3812 KB Output is correct
3 Correct 73 ms 7676 KB Output is correct
4 Correct 80 ms 7164 KB Output is correct
5 Correct 91 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 4264 KB Output is correct
2 Correct 24 ms 4224 KB Output is correct
3 Correct 108 ms 15416 KB Output is correct
4 Correct 116 ms 15128 KB Output is correct
5 Correct 82 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 442 ms 4556 KB Output is correct
2 Correct 304 ms 3752 KB Output is correct
3 Correct 422 ms 3668 KB Output is correct
4 Correct 515 ms 4132 KB Output is correct
5 Correct 415 ms 4052 KB Output is correct
6 Correct 530 ms 4500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 6184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 8040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Execution timed out 1092 ms 3976 KB Time limit exceeded
3 Halted 0 ms 0 KB -