Submission #1068576

# Submission time Handle Problem Language Result Execution time Memory
1068576 2024-08-21T10:43:33 Z parsadox2 Beech Tree (IOI23_beechtree) C++17
9 / 100
2000 ms 32784 KB
#include "beechtree.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
int n , col[N] , m , sbt[N] , is_path[N] , cnt[N];
vector <int> adj[N];
vector <int> all , p;

void Dfs(int v)
{
    sbt[v] = 1;
    for(auto u : adj[v])
    {
        Dfs(u);
        sbt[v] += sbt[u];
    }
    if(adj[v].size() == 1)
    {
        int c = adj[v][0];
        if(sbt[c] == 1)
            is_path[v] = col[c];
        else if(col[c] == is_path[c])
            is_path[v] = col[c];
        else
            is_path[v] = -1;
    }
    else if(adj[v].size() > 1)
    {
        is_path[v] = -1;
    }
}

void Dfs_all(int v)
{
    all.push_back(v);
    cnt[col[v]] = 0;
    for(auto u : adj[v])
        Dfs_all(u);
}

bool Solve(int v)
{
    all.clear();
    Dfs_all(v);
    sort(all.begin() , all.end());
    bool flg = false;
    do{
        for(auto u : all)
            cnt[col[u]] = 0;
        bool tmp = true;
        for(int i = 1 ; i < all.size() ; i++)
        {
            if(all[cnt[col[all[i]]]] != p[all[i]])
                tmp = false;
            cnt[col[all[i]]]++;
        }
        flg |= tmp;
    }while(next_permutation(all.begin() , all.end()));
    return flg;
}

vector<int> beechtree(int nn, int mm, vector<int> P, vector<int> C)
{
    n = nn;  
    m = mm;
    p = P;
    for(int i = 1 ; i < n ; i++)
    {
        adj[P[i]].push_back(i);
        col[i] = C[i];
    }
    Dfs(0);
    vector <int> res(n , 0);
    for(int i = 0 ; i < n ; i++)
    {
        if(is_path[i] != -1)
        {
            res[i] = true;
            continue;
        }
        res[i] = Solve(i);
    }
    return res;
}

Compilation message

beechtree.cpp: In function 'bool Solve(int)':
beechtree.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int i = 1 ; i < all.size() ; i++)
      |                         ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Execution timed out 2097 ms 6748 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6744 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 1 ms 7000 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6748 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 1 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6744 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Execution timed out 2053 ms 32784 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2074 ms 6748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 7000 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Execution timed out 2053 ms 32784 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Execution timed out 2097 ms 6748 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 7000 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6748 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 1 ms 6744 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 2 ms 7004 KB Output is correct
26 Execution timed out 2063 ms 7004 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Execution timed out 2097 ms 6748 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 7000 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6748 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 1 ms 6744 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 2 ms 7004 KB Output is correct
26 Execution timed out 2063 ms 7004 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Execution timed out 2097 ms 6748 KB Time limit exceeded
3 Halted 0 ms 0 KB -