이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// M
#include<bits/stdc++.h>
#include "split.h"
using namespace std;
const int N = 100005;
int n, K[3], Cl[3], M[N], SZ[N], MR[N];
vector < int > C, vec, Adj[N], Ad[N], G[N];
void DFS(int v)
{
M[v] = SZ[v] = 1;
for (int u : Adj[v])
if (!M[u])
{
Ad[v].push_back(u);
Ad[u].push_back(v);
DFS(u);
SZ[v] += SZ[u];
}
}
int Centroid(int v, int p = -1)
{
for (int u : Ad[v])
if (u != p && SZ[u] * 2 > n)
return Centroid(u, v);
return v;
}
void DFS2(int v, int p = -1)
{
SZ[v] = 1;
for (int u : Ad[v])
if (u != p)
DFS2(u, v), SZ[v] += SZ[u];
}
void Color(int v, int p, int c)
{
if (!K[c])
return ;
C[v] = Cl[c];
K[c] --;
for (int u : Ad[v])
if (u != p && !C[u])
Color(u, v, c);
}
void MarkAs(int v, int p, int mr)
{
MR[v] = mr;
for (int u : Ad[v])
if (u != p)
MarkAs(u, v, mr);
}
void Go(int v)
{
M[v] = 1;
vec.push_back(v);
for (int u : G[v])
if (!M[u]) Go(u);
}
vector < int > find_split(int _n, int a, int b, int c, vector < int > V, vector < int > U)
{
n = _n;
K[0] = a; K[1] = b; K[2] = c;
Cl[0] = 1; Cl[1] = 2; Cl[2] = 3;
for (int i = 0; i < 3; i ++)
for (int j = i + 1; j < 3; j ++)
if (K[i] > K[j])
swap(K[i], K[j]), swap(Cl[i], Cl[j]);
int m = (int)V.size();
for (int i = 0; i < m; i ++)
{
Adj[V[i]].push_back(U[i]);
Adj[U[i]].push_back(V[i]);
}
DFS(0);
int Cent = Centroid(0);
DFS2(Cent);
C = vector < int > (n, 0);
for (int u : Ad[Cent])
if (SZ[u] >= K[0])
{
Color(u, Cent, 0);
Color(Cent, -1, 1);
for (int i = 0; i < n; i ++)
if (!C[i])
C[i] = Cl[2];
return C;
}
for (int u : Ad[Cent])
MarkAs(u, Cent, u);
for (int i = 0; i < m; i ++)
if (V[i] != Cent && U[i] != Cent && MR[V[i]] != MR[U[i]])
G[MR[V[i]]].push_back(MR[U[i]]),
G[MR[U[i]]].push_back(MR[V[i]]);
memset(M, 0, sizeof(M));
for (int u : Ad[Cent])
if (!MR[u])
{
vec.clear();
Go(u);
int sz = 0;
for (int v : vec)
sz += SZ[v];
if (sz >= K[0])
{
for (int v : vec)
Color(v, Cent, 0);
Color(Cent, -1, 1);
for (int i = 0; i < n; i ++)
if (!C[i])
C[i] = Cl[2];
return C;
}
}
return C;
}
# | 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... |