이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// failed/sol_gyp_wa.cpp
// #include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
const int c = 200005;
int n, szint[c], cl[c];
vector<int> sz[c], szin[c], ans;
bool ism[c];
void dfs(int a)
{
for (auto x : sz[a])
{
szint[x] = szint[a] + 1;
dfs(x);
if (ism[x])
{
ism[a] = 1;
}
}
}
bool is_subset(int a, int b)
{
// a-ban van tobb
int pos = 0, si = szin[b].size();
for (auto x : szin[a])
{
if (pos < si && x == szin[b][pos])
{
pos++;
}
}
return (pos == si);
}
vector<pair<int, int>> sor;
void dfs2(int a)
{
int si = sz[a].size();
sor.push_back({-si, a});
for (auto x : sz[a])
{
dfs2(x);
}
}
bool solve(int a)
{
// cout << "solve " << a << "\n";
dfs2(a);
sort(sor.begin(), sor.end());
int si = sor.size();
bool jo = 1;
for (int i = 1; i < si; i++)
{
if (!is_subset(sor[i - 1].second, sor[i].second))
{
jo = 0;
}
}
for (int i = 0; i < si; i++)
{
for (int j = i + 1; j < si; j++)
{
int a = sor[i].second, b = sor[j].second;
if (cl[a] == cl[b] && a > b)
{
jo = 0;
}
}
}
sor.clear();
return jo;
}
std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C)
{
n = N;
for (int i = 1; i < n; i++)
{
sz[P[i]].push_back(i);
szin[P[i]].push_back(C[i]);
cl[i] = C[i];
}
for (int i = 0; i < n; i++)
{
sort(szin[i].begin(), szin[i].end());
for (int j = 1; j < szin[i].size(); j++)
{
if (szin[i][j] == szin[i][j - 1])
{
ism[i] = 1;
}
}
}
dfs(0);
for (int i = 0; i < n; i++)
{
if (ism[i])
{
ans.push_back(0);
}
else
{
ans.push_back(solve(i));
}
}
return ans;
}
/*
int main() {
int N, M;
assert(2 == scanf("%d %d", &N, &M));
std::vector<int> P(N);
for(int i = 0; i < N; ++i)
assert (1 == scanf("%d", &P[i]));
std::vector<int> C(N);
for(int i = 0; i < N; ++i)
assert (1 == scanf("%d", &C[i]));
fclose(stdin);
std::vector<int> res = beechtree(N, M, P, C);
int n = res.size();
for (int i = 0; i < n; ++i) {
if (i > 0)
printf(" ");
printf("%d", res[i]);
}
printf("\n");
fclose(stdout);
return 0;
}
*/
/*
3 3
-1 0 0
0 1 2
*/
/*
18 3
-1 0 0 0 1 1 1 2 2 3 3 3 4 4 5 10 11 11
0 1 2 3 1 2 3 1 3 3 2 1 1 2 2 1 2 3
*/
컴파일 시 표준 에러 (stderr) 메시지
beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:87:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int j = 1; j < szin[i].size(); j++)
| ~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |