This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// na mn tanha nistam :)
#include <bits/stdc++.h>
#include "split.h"
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
const int maxn5 = 4e5 + 10;
int a, b, c, n, sz[maxn5], ed1, ed2;
int st[3] = {1, 2, 3}, num[3];
vector <int> ret, adj[maxn5];
bool mark[maxn5];
void dfs(int v){
mark[v] = true;
sz[v] = 1;
if(ed1 != -1)
return;
for(auto u : adj[v]) if(!mark[u] && ed1 == -1){
dfs(u);
sz[v] += sz[u];
if(ed1 != -1)
return;
for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) if(i != j && ed1 == -1){
if(sz[u] >= num[i] && n - sz[u] >= num[j]){
int keep0 = i, keep1 = j;
int keep2 = (i != 0 && j != 0 ? 0 : (i != 1 && j != 1 ? 1 : 2));
int tmp[3] = {num[keep0], num[keep1], num[keep2]};
num[0] = tmp[0];
num[1] = tmp[1];
num[2] = tmp[2];
ed1 = u;
ed2 = v;
st[0] = keep0 + 1;
st[1] = keep1 + 1;
st[2] = keep2 + 1;
return;
}
}
}
}
void dfs_solve(int v, int ty){
mark[v] = true;
num[ty]--;
ret[v] = st[ty];
//cout << v << ' ' << ty << ' ' << num[ty] << endl;
for(auto u : adj[v]) if(!mark[u] && num[ty])
dfs_solve(u, ty);
}
vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) {
n = N;
num[0] = a;
num[1] = b;
num[2] = c;
ret.resize(n);
fill(all(ret), 0);
for(int i = 0; i < int(p.size()); i++){
adj[p[i]].pb(q[i]);
adj[q[i]].pb(p[i]);
}
ed1 = ed2 = -1;
dfs(0);
if(ed1 == -1)
return ret;
//cout << ed1 << ' ' << ed2 << ' ' << num[0] << ' ' << num[1] << ' ' << num[2] << endl;
memset(mark, false, sizeof mark);
mark[ed1] = mark[ed2] = true;
dfs_solve(ed1, 0);
dfs_solve(ed2, 1);
for(int i = 0; i < n; i++) if(!ret[i])
ret[i] = st[2];
return ret;
}
# | 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... |