Submission #848311

# Submission time Handle Problem Language Result Execution time Memory
848311 2023-09-12T04:59:18 Z math_rabbit_1028 Beech Tree (IOI23_beechtree) C++17
0 / 100
102 ms 72464 KB
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n, m;
vector<int> p, c;
vector<int> adj[202020], res;
int sz[202020];
int has[202020];

void solve(int v) {
    sz[v] = 1;
    for (int i = 0; i < adj[v].size(); i++) {
        int u = adj[v][i];
        solve(u);
        sz[v] += sz[u];
        has[v] += has[u];
    }
    if (adj[v].size() == 0) has[v] = 0;
    else has[v]++;
    if (has[v] > 2) return;
    priority_queue< pair<pii, int> > pq;
    vector<int> vec;
    pq.push({{sz[v], 0}, v});
    while (!pq.empty()) {
        int now = pq.top().second;
        vec.push_back(now);
        pq.pop();
        for (int i = 0; i < adj[now].size(); i++) {
            int u = adj[now][i];
            pq.push({{sz[u], -vec.size()}, u});
        }
    }

    map<int, int> cnt;
    for (int i = 1; i < sz[v]; i++) {
        int now = vec[i], par; 
        if (cnt.find(c[now]) == cnt.end()) {
            par = vec[0];
            cnt.insert({c[now], 1});
        }
        else {
            par = vec[cnt[c[now]]];
            cnt[c[now]]++;
        }

        if (par != p[now]) {
            res[v] = 0;
            return;
        }
    }
}

vector<int> beechtree(int N, int M, vector<int> P, vector<int> C) {
    n = N; m = M; p = P; c = C;
    for (int i = 1; i < n; i++) {
        adj[p[i]].push_back(i);
    }

    for (int i = 0; i < n; i++) res.push_back(1);
    
    solve(0);

    return res;
}

Compilation message

beechtree.cpp: In function 'void solve(int)':
beechtree.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < adj[v].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~
beechtree.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int i = 0; i < adj[now].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 2 ms 6504 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 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Incorrect 2 ms 6492 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Incorrect 2 ms 6492 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6492 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Incorrect 102 ms 72464 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 2 ms 6492 KB Output is correct
2 Incorrect 2 ms 6504 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 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Incorrect 2 ms 6488 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 2 ms 6492 KB Output is correct
2 Incorrect 2 ms 6504 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 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Incorrect 2 ms 6488 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 2 ms 6492 KB Output is correct
2 Incorrect 2 ms 6504 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -