This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "split.h"
#include <algorithm>
using namespace std;
const int mxn = 1e5+5;
bool visited[mxn];
int sz[mxn];
vector<int> color, adj[mxn];
void dfs(int u) {
visited[u] = true;
sz[u] = 1;
for(int v : adj[u]) if(!visited[v]) {
dfs(v); sz[u] += sz[v];
}
}
int find_centroid(int u, int n) {
visited[u] = true;
for(int v : adj[u]) if(!visited[u] && 2*sz[u]>n) {
return find_centroid(v, u);
}
return u;
}
void mark(int u, int m, int &cnt) {
if(cnt <= 0) return;
visited[u] = true;
color[u] = m;
cnt--;
for(int v : adj[u]) if(!visited[v]) {
mark(v, m, cnt);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
for(int i = 0; i < p.size(); i++) {
int u = p[i], v = q[i];
adj[u].push_back(v), adj[v].push_back(u);
}
dfs(0);
fill(visited, visited+n, false);
int centroid = find_centroid(0, n);
fill(visited, visited+n, false);
vector<pair<int, int>> groups = {pair<int, int>{a, 1}, pair<int, int>{b, 2}, pair<int, int>{c, 3}};
sort(groups.begin(), groups.end());
color.resize(n, groups[2].second);
int small_group = -1;
int cnt;
for(int u : adj[centroid]) {
if(sz[u] >= groups[0].first) {
visited[centroid] = true;
cnt = groups[centroid].first;
mark(u, groups[centroid].second, cnt);
small_group = u;
}
break;
}
if(small_group == -1) return vector<int>(n, 0);
fill(visited, visited+n, false);
visited[small_group] = true;
cnt = groups[1].first;
mark(centroid, groups[1].second, cnt);
return color;
}
Compilation message (stderr)
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | 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... |