Submission #1065628

# Submission time Handle Problem Language Result Execution time Memory
1065628 2024-08-19T10:09:21 Z Zicrus Beech Tree (IOI23_beechtree) C++17
9 / 100
126 ms 33364 KB
#include <bits/stdc++.h>
#include "beechtree.h"
using namespace std;
 
typedef long long ll;

ll n;
vector<int> c;
vector<int> res;
vector<vector<ll>> adj;
vector<pair<ll, ll>> szId;
vector<ll> dep;

ll dfsDep(ll cur) {
    ll d = 0;
    for (auto &e : adj[cur]) {
        d = max(d, dfsDep(e)+1);
    }
    return dep[cur] = d;
}

void dfsSzId(ll cur) {
    szId.push_back({adj[cur].size(), cur});
    for (auto &e : adj[cur]) {
        dfsSzId(e);
    }
}

void solve2(ll root) {
    szId.clear();
    dfsSzId(root);
    sort(szId.begin(), szId.end());

    unordered_set<ll> used;
    if (adj[root].size() != szId.back().first) res[root] = 0;
    for (auto &e : adj[root]) {
        if (used.count(c[e]))
            res[root] = 0;
        used.insert(c[e]);
    }
    for (int i = n-1; i >= 1; i--) {
        unordered_set<ll> nw;
        for (auto &e : adj[szId[i].second]) {
            if (!used.count(c[e]))
                res[root] = 0;
            if (nw.count(c[e]))
                res[szId[i].second] = res[root] = 0;
            nw.insert(c[e]);
        }
        used = nw;
    }
}

void dfsSol(ll cur) {
    if (dep[cur] <= 2) return solve2(cur);
    res[cur] = 0;
    for (auto &e : adj[cur]) {
        dfsSol(e);
    }
}
 
vector<int> beechtree(int n1, int m, vector<int> p, vector<int> c1) {
    n = n1; c = c1;
    res = vector<int>(n, 1);
    adj = vector<vector<ll>>(n);
    dep = vector<ll>(n);
    for (int i = 1; i < n; i++) {
        adj[p[i]].push_back(i);
    }
    dfsDep(0);
    szId = vector<pair<ll, ll>>(n);
    for (int i = 0; i < n; i++) {
        szId[i] = {adj[i].size(), i};
    }
    sort(szId.begin(), szId.end());
    
    dfsSol(0);

    return res;
}

#ifdef TEST
#include "grader.cpp"
#endif

Compilation message

beechtree.cpp: In function 'void solve2(ll)':
beechtree.cpp:35:26: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   35 |     if (adj[root].size() != szId.back().first) res[root] = 0;
      |         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 51 ms 9204 KB Output is correct
16 Correct 55 ms 8788 KB Output is correct
17 Correct 63 ms 8784 KB Output is correct
18 Correct 51 ms 9044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 126 ms 30952 KB Output is correct
6 Correct 106 ms 33364 KB Output is correct
7 Incorrect 1 ms 348 KB 2nd lines differ - on the 21st token, expected: '1', found: '0'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -