Submission #342469

# Submission time Handle Problem Language Result Execution time Memory
342469 2021-01-02T07:38:10 Z leinad2 Spring cleaning (CEOI20_cleaning) C++17
34 / 100
1000 ms 25964 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++<cnt;)
        {
            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 1088 ms 11628 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 28 ms 13292 KB Output is correct
2 Correct 29 ms 13164 KB Output is correct
3 Correct 62 ms 17384 KB Output is correct
4 Correct 89 ms 18148 KB Output is correct
5 Correct 112 ms 20328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13824 KB Output is correct
2 Correct 30 ms 13820 KB Output is correct
3 Correct 73 ms 24044 KB Output is correct
4 Correct 108 ms 25964 KB Output is correct
5 Correct 66 ms 22764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 11908 KB Output is correct
2 Correct 288 ms 11372 KB Output is correct
3 Correct 402 ms 11116 KB Output is correct
4 Correct 424 ms 11628 KB Output is correct
5 Correct 408 ms 11756 KB Output is correct
6 Correct 458 ms 11932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 14060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 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 1088 ms 11628 KB Time limit exceeded