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 <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;
vector <ll> V;
vector <ll> adj[100000], E[200000];
bool ap[200000], ok;
vector <ll> G[200000], X[100000];
bool visited[100000], marked[100000];
array<ll, 2> T[3];
queue <ll> Q, P;
ll m, k, A[3], B[3], in[100000], low[100000], st[100000], sz[200000], F[200000], C[200000], cnt;
void tar(ll u, ll p) {
V.push_back(u);
low[u] = st[u] = ++cnt;
ll rch = 0;
for (auto v : adj[u]) {
if (!st[v]) {
++rch;
tar(v, u);
low[u] = min(low[u], low[v]);
if (low[v] >= st[u]) {
if (p != -1) ap[u] = 1;
while (!V.empty()) {
auto x = V.back();
V.pop_back();
X[x].push_back(k);
G[k].push_back(x);
if (x == v) break;
}
X[u].push_back(k);
G[k].push_back(u);
++k;
}
}
else if (v != p) {
low[u] = min(low[u], st[v]);
}
}
if (p == -1 & rch > 1) ap[u] = 1;
}
void dfs(ll u, ll w) {
visited[u] = 1;
for (auto v : adj[u]) {
if (!visited[v] && !C[v]) {
if (B[w] < A[w]) {
F[v] = w;
++B[w];
}
else F[v] = 2;
dfs(v, w);
}
}
}
void find(ll u, ll w) {
if (B[w] < A[w]) {
++B[w];
F[u] = w;
}
else F[u] = 2;
dfs(u, w);
for (auto v : adj[u]) {
if (C[v] && !visited[v]) {
find(v, w);
}
}
}
void solve(ll u, ll p) {
if (ap[u]) ++sz[u];
else sz[u] += G[u].size() - E[u].size();
ll mx = -1;
for (auto v : E[u]) {
if (v != p) {
solve(v, u);
sz[u] += sz[v];
mx = max(mx, sz[v]);
}
}
mx = max(mx, m - sz[u]);
if (!ok && !ap[u] && mx <= m-A[0]) {
if (mx >= A[1]) {
if (m-sz[u] == mx) {
F[p] = 1;
}
else {
for (auto v : E[u]) {
if (v != p) {
if (sz[v] == mx) {
F[v] = 1;
break;
}
}
}
}
for (auto v : G[u]) {
C[v] = 1;
}
for (auto v : G[u]) {
if (F[v]) {
++B[1];
dfs(v, 1);
}
}
for (auto v : G[u]) {
if (!F[v]) {
find(v, 0);
break;
}
}
}
else {
for (auto v : G[u]) {
if (B[0] < A[0]) {
++B[0];
F[v] = 0;
dfs(v, 0);
}
else if (B[1] < A[1]) {
++B[1];
F[v] = 1;
dfs(v, 0);
}
else {
F[v] = 2;
dfs(v, 0);
}
}
}
ok = 1;
return;
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
A[0] = T[0][0] = a, A[1] = T[1][0] = b, A[2] = T[2][0] = c;
T[1][1] = 1, T[2][1] = 2;
sort(A, A+3);
sort(T, T+3);
m = n;
k = n;
for (int i=0; i<p.size(); ++i) {
adj[p[i]].push_back(q[i]);
adj[q[i]].push_back(p[i]);
}
tar(0, -1);
for (int i=0; i<n; ++i) {
if (ap[i]) {
for (auto u : X[i]) {
E[i].push_back(u);
E[u].push_back(i);
}
}
}
solve(n, -1);
vector <int> U;
if (ok) {
U.clear();
for (int i=0; i<n; ++i) {
U.push_back(T[F[i]][1]+1);
}
}
else {
for (int i=0; i<n; ++i) {
U.push_back(F[i]);
}
}
return U;
}
Compilation message (stderr)
split.cpp: In function 'void tar(long long int, long long int)':
split.cpp:47:8: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
47 | if (p == -1 & rch > 1) ap[u] = 1;
| ~~^~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:151:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
151 | 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... |