이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#include "split.h"
using namespace std;
constexpr static int MXN = 1e5;
vector<int> g[MXN];
int subsize[MXN], n;
vector<int> res;
array<array<int, 2>, 3> arr;
array<int, 3> counter;
void dfs2(int node, int parent, int val)
{
if (counter[val] == arr[val][0])
return;
counter[val]++;
res[node] = arr[val][1];
for (int c : g[node])
if (c != parent)
dfs2(c, node, val);
}
bool dfs1(int node, int parent)
{
subsize[node] = 1;
for (int c : g[node])
{
if (c != parent)
{
bool out = dfs1(c, node);
if (out)
return true;
subsize[node] += subsize[c];
}
}
if (subsize[node] >= arr[0][0] && n - subsize[node] >= arr[1][0])
{
dfs2(node, parent, 0);
dfs2(parent, node, 1);
return true;
}
else if (subsize[node] >= arr[1][0] && n - subsize[node] >= arr[0][0])
{
dfs2(node, parent, 1);
dfs2(parent, node, 0);
return true;
}
return false;
}
vector<int> find_split(int _n, int a, int b, int c, vector<int> p, vector<int> q)
{
n = _n;
res = vector<int>(n, 0);
for (int i = 0; i < p.size(); i++)
{
g[p[i]].pb(q[i]);
g[q[i]].pb(p[i]);
}
arr[0] = {a, 1};
arr[1] = {b, 2};
arr[2] = {c, 3};
sort(arr.begin(), arr.end());
if (dfs1(0, -1))
for (int i = 0; i < n; i++)
if (!res[i])
res[i] = arr[2][1];
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int i = 0; i < p.size(); i++)
| ~~^~~~~~~~~~
# | 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... |