Submission #342470

# Submission time Handle Problem Language Result Execution time Memory
342470 2021-01-02T07:43:59 Z leinad2 Spring cleaning (CEOI20_cleaning) C++17
34 / 100
1000 ms 26108 KB
#include<bits/stdc++.h>
using namespace std;
int n, i, j, k, r, q, a, b, cnt, sz[200010];
vector<int>adj2[200010], adj[200010];
void dfs(int v, int par)
{
    sz[v]=0;
    if(adj[v].size()==1)
    {
        sz[v]=1;
        return;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int p=adj[v][i];
        if(p==par)continue;
        dfs(p, v);
        sz[v]+=sz[p];
    }
}
int main()
{
    for(scanf("%d %d", &n, &q);++i<n;)
    {
        scanf("%d %d", &a, &b);
        adj2[a].push_back(b);
        adj2[b].push_back(a);
    }
    for(i=0;i++<n;)
    {
        if(adj2[i].size()>1)
        {
            r=i;
            break;
        }
    }
    while(q--)
    {
        int ans=n-1;
        for(i=0;i++<2*n;)adj[i].clear();
        for(i=0;i++<n;)
        {
            for(j=0;j<adj2[i].size();j++)
            {
                adj[i].push_back(adj2[i][j]);
            }
        }
        cnt=n;
        scanf("%d", &a);
        while(a--)
        {
            scanf("%d", &b);
            adj[b].push_back(++cnt);
            adj[cnt].push_back(b);
            ans++;
        }
        dfs(r, 0);
        if(sz[r]%2)
        {
            puts("-1");
            continue;
        }
        for(i=0;i++<n;)
        {
            if(sz[i]%2==0)ans++;
        }
        printf("%d\n", ans-1);
    }
}

Compilation message

cleaning.cpp: In function 'void dfs(int, int)':
cleaning.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i<adj[v].size();i++)
      |                 ~^~~~~~~~~~~~~~
cleaning.cpp: In function 'int main()':
cleaning.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             for(j=0;j<adj2[i].size();j++)
      |                     ~^~~~~~~~~~~~~~~
cleaning.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     for(scanf("%d %d", &n, &q);++i<n;)
      |         ~~~~~^~~~~~~~~~~~~~~~~
cleaning.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
cleaning.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
cleaning.cpp:52:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |             scanf("%d", &b);
      |             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9708 KB Output is correct
2 Execution timed out 1096 ms 11500 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13164 KB Output is correct
2 Correct 28 ms 13164 KB Output is correct
3 Correct 60 ms 17384 KB Output is correct
4 Correct 85 ms 18148 KB Output is correct
5 Correct 105 ms 20348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13804 KB Output is correct
2 Correct 30 ms 13804 KB Output is correct
3 Correct 77 ms 24132 KB Output is correct
4 Correct 110 ms 26108 KB Output is correct
5 Correct 62 ms 22892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 453 ms 11884 KB Output is correct
2 Correct 288 ms 11244 KB Output is correct
3 Correct 425 ms 11136 KB Output is correct
4 Correct 456 ms 11628 KB Output is correct
5 Correct 399 ms 11756 KB Output is correct
6 Correct 450 ms 11756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1100 ms 14060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 16620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9708 KB Output is correct
2 Execution timed out 1096 ms 11500 KB Time limit exceeded