Submission #1030051

# Submission time Handle Problem Language Result Execution time Memory
1030051 2024-07-21T17:40:21 Z Mr_Husanboy Beech Tree (IOI23_beechtree) C++17
8 / 100
138 ms 36820 KB
#include "beechtree.h"
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second

using namespace std;
typedef pair<int, int> pii;
const int N = 2e5 + 1;

struct Graph
{
    int cnt[N];
    bool gpar[N];
    map<int, vector<int>> col[N];
} graph;

bool check(int u)
{
    vector<int> nleaf;
    for (auto &pr : graph.col[u])
    {
        if (pr.yy.size() > 1)
        {
            return false;
        }
        for (int v : pr.yy)
        {
            if (!graph.col[v].empty())
            {
                nleaf.push_back(v);
            }
        }
    }
    if (nleaf.size() > 1)
    {
        return false;
    }
    if (nleaf.size() == 0)
    {
        return true;
    }
    int v = nleaf[0];
    if (graph.gpar[v])
    {
        return false;
    }
    bool res = true;
    for (auto &pr : graph.col[v])
    {
        res &= graph.col[u].count(pr.xx);
    }
    return res;
}

vector<int> beechtree(int n, int m, vector<int> P, vector<int> C)
{
    for (int i = 1; i < n; ++i)
    {
        int p = P[i];
        int c = C[i];
        if (!graph.col[p].count(c))
        {
            graph.col[p][c] = vector<int>();
        }
        graph.col[p][c].push_back(i);
        if (P[i] != 0)
        {
            graph.gpar[P[P[i]]] = true;
        }
    }
    vector<int> ans;
    for (int i = 0; i < n; ++i)
    {
        ans.push_back(check(i));
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Incorrect 4 ms 10584 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 5 ms 10588 KB Output is correct
3 Incorrect 5 ms 10588 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 5 ms 10588 KB Output is correct
3 Incorrect 5 ms 10588 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10588 KB Output is correct
2 Correct 4 ms 10588 KB Output is correct
3 Correct 4 ms 10588 KB Output is correct
4 Correct 5 ms 10588 KB Output is correct
5 Correct 4 ms 10588 KB Output is correct
6 Correct 5 ms 10584 KB Output is correct
7 Correct 4 ms 10588 KB Output is correct
8 Correct 5 ms 10588 KB Output is correct
9 Incorrect 5 ms 10588 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 5 ms 10588 KB Output is correct
3 Correct 5 ms 10588 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 80 ms 36820 KB Output is correct
6 Correct 75 ms 36812 KB Output is correct
7 Correct 4 ms 10588 KB Output is correct
8 Correct 3 ms 10588 KB Output is correct
9 Correct 5 ms 10844 KB Output is correct
10 Correct 5 ms 10844 KB Output is correct
11 Correct 82 ms 34644 KB Output is correct
12 Correct 138 ms 34828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Incorrect 4 ms 10584 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 5 ms 10588 KB Output is correct
3 Correct 5 ms 10588 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9816 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 10588 KB Output is correct
10 Correct 4 ms 10584 KB Output is correct
11 Correct 3 ms 10588 KB Output is correct
12 Correct 4 ms 10420 KB Output is correct
13 Correct 4 ms 10588 KB Output is correct
14 Correct 5 ms 10404 KB Output is correct
15 Correct 5 ms 10588 KB Output is correct
16 Incorrect 4 ms 10588 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Incorrect 4 ms 10584 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 5 ms 10588 KB Output is correct
3 Correct 5 ms 10588 KB Output is correct
4 Correct 4 ms 10588 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9816 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 10588 KB Output is correct
10 Correct 4 ms 10584 KB Output is correct
11 Correct 3 ms 10588 KB Output is correct
12 Correct 4 ms 10420 KB Output is correct
13 Correct 4 ms 10588 KB Output is correct
14 Correct 5 ms 10404 KB Output is correct
15 Correct 5 ms 10588 KB Output is correct
16 Incorrect 4 ms 10588 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Incorrect 4 ms 10584 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -