제출 #1065626

#제출 시각아이디문제언어결과실행 시간메모리
1065626Zicrus참나무 (IOI23_beechtree)C++17
9 / 100
117 ms36532 KiB
#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;
    }
}
 
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());
    
    solve2(0);

    return res;
}

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

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...