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 <bits/stdc++.h>
using namespace std;
#define pb push_back
const int len = 1e5+5;
vector<int> adj[len], out;
int vis[len], n, sz1, sz2, sz3, col1, col2, col3;
void paint(int u, int p, int &rem, int col){
//printf("painting: u = %d, p = %d, rem = %d, col = %d\n", u, p, rem, col);
vis[u] = col, rem--;
if (rem == 0) return;
for (auto v: adj[u]){
if (v == p || vis[v]) continue;
paint(v, u, rem, col);
if (rem == 0) return;
}
}
struct{
int sz[len];
int fix(int u, int p = 0){
//printf("fix: u = %d, p = %d\n", u, p);
int ans = 1;
for (auto v: adj[u]){
if (v == p) continue;
int sz = fix(v, u);
ans += sz;
if (sz1 <= sz && sz2 <= n-sz){
paint(v, u, sz1, col1);
paint(u, v, sz2, col2);
return 0;
}
if (sz1 <= n-sz && sz2 <= sz){
paint(u, v, sz1, col1);
paint(v, u, sz2, col2);
return 0;
}
}
return ans;
}
void solve(){
fix(1);
int yes = 0;
for (int i = 1; i <= n; i++)
if (vis[i]) yes = 1;
if (!yes) return;
for (int i = 1; i <= n; i++){
if (!vis[i]) vis[i] = col3;
out[i-1] = vis[i];
}
}
} sub3;
struct{
void solve(){
for (int i = 1; i <= n; i++)
if (!vis[i]){
paint(i, i, sz2, col2);
break;
}
for (int i = 1; i <= n; i++)
if (!vis[i]){
paint(i, i, sz1, col1);
break;
}
for (int i = 1; i <= n; i++){
if (!vis[i])
vis[i] = col3;
out[i-1] = vis[i];
}
}
} sub12;
vector<int> find_split(int N, int A, int B, int C, vector<int> P, vector<int> Q) {
n = N;
sz1 = A, sz2 = B, sz3 = C;
col1 = 1, col2 = 2, col3 = 3;
if (sz2 < sz1)
swap(sz2, sz1), swap(col2, col1);
if (sz3 < sz1)
swap(sz3, sz1), swap(col3, col1);
if (sz3 < sz2)
swap(sz3, sz2), swap(col3, col2);
//printf("sz1 = %d, sz2 = %d, sz3 = %d\n", sz1, sz2, sz3);
//printf("col1 = %d, col2 = %d, col3 = %d\n", col1, col2, col3);
for (int i = 0; i < P.size(); i++){
int a = P[i], b = Q[i];
a++, b++;
adj[a].pb(b);
adj[b].pb(a);
}
out.resize(n, 0);
if (P.size() == n-1)
sub3.solve();
else
sub12.solve();
return out;
}
Compilation message (stderr)
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:104:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for (int i = 0; i < P.size(); i++){
| ~~^~~~~~~~~~
split.cpp:112:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
112 | if (P.size() == n-1)
| ~~~~~~~~~^~~~~~
# | 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... |