Submission #841640

# Submission time Handle Problem Language Result Execution time Memory
841640 2023-09-01T19:01:35 Z Enchom Beech Tree (IOI23_beechtree) C++17
0 / 100
3 ms 15356 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 con[N];
    vector<pii> srt[N];
    map<int, vector<int>> col[N];
} graph;

bool check(int v, int u, bool equalStuff)
{
    for (auto &pr : graph.col[v])
    {
        auto &[col, vec] = pr;
        auto it = graph.col[u].find(col);
        if (it == graph.col[u].end() || (!equalStuff && graph.cnt[vec[0]] > graph.cnt[it->yy[0]]))
        {
            return false;
        }
    }
    return true;
}

int dfs(int u)
{
    graph.cnt[u] = 1;
    graph.con[u] = true;

    for (auto &pr : graph.col[u])
    {
        auto &[col, vec] = pr;
        graph.con[u] &= vec.size() == 1;

        for (int v : vec)
        {
            int cnv = dfs(v);
            if (cnv == -1)
            {
                graph.con[u] = false;
            }
            else
            {
                graph.cnt[u] += cnv;
            }
            for (pii p : graph.srt[v])
            {
                graph.srt[u].push_back(p);
            }
        }
    }
    graph.srt[u].push_back({graph.cnt[u], u});
    sort(all(graph.srt[u]));

    for (int i = 0; i < graph.srt[u].size() - 1; ++i)
    {
        for (int j = i + 1; j < graph.srt[u].size() - 1; j++)
        {
            graph.con[u] = graph.con[u] & check(graph.srt[u][i].yy, graph.srt[u][j].yy, false);
        }
    }
    return graph.con[u] ? graph.cnt[u] : -1;
}

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);
    }
    dfs(0);

    vector<int> ans;
    for (int i = 0; i < n; ++i)
        ans.push_back(graph.con[i]);
    return ans;
}

Compilation message

beechtree.cpp: In function 'int dfs(int)':
beechtree.cpp:64:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for (int i = 0; i < graph.srt[u].size() - 1; ++i)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~
beechtree.cpp:66:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int j = i + 1; j < graph.srt[u].size() - 1; j++)
      |                             ~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Incorrect 3 ms 15196 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Incorrect 3 ms 15196 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15192 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15300 KB Output is correct
4 Correct 3 ms 15196 KB Output is correct
5 Incorrect 3 ms 15356 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Incorrect 3 ms 15196 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15348 KB Output is correct
4 Correct 3 ms 15196 KB Output is correct
5 Incorrect 3 ms 15196 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Incorrect 3 ms 15196 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15348 KB Output is correct
4 Correct 3 ms 15196 KB Output is correct
5 Incorrect 3 ms 15196 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Incorrect 3 ms 15196 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 3 ms 15348 KB Output is correct
4 Correct 3 ms 15196 KB Output is correct
5 Incorrect 3 ms 15196 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -