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 <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
vector<int> edge[100005];
int sub[100005];
int parent[100005];
int check[100005];
void dfs(int root)
{
sub[root] = 1;
for (auto&e : edge[root])
{
if (e == parent[root])
continue;
parent[e] = root;
dfs(e);
sub[root] += sub[e];
}
}
void mark(int root, vector<int>& num, int& a, int& b)
{
for (auto& e : edge[root])
{
if (e == parent[root])
continue;
if (check[e] == 0)
check[e] = check[root];
}
if (check[root] == 1 && a > 0)
{
num[root] = 1;
a--;
}
if (check[root] == 2 && b > 0)
{
num[root] = 2;
b--;
}
for (auto& e : edge[root])
{
if (e == parent[root])
continue;
mark(e, num, a, b);
}
}
void solve(vector<int>& num, int now, int k, int& count)
{
if (count == 0)
return;
num[now] = k;
count--;
for (auto& e : edge[now])
{
if (num[e] != -1)
continue;
solve(num, e, k, count);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q)
{
memset(parent, -1, sizeof(parent));
for (int i = 0; i < p.size(); i++)
{
edge[p[i]].push_back(q[i]);
edge[q[i]].push_back(p[i]);
}
if (p.size() == n - 1)
{
vector<int> num(n, 0);
dfs(0);
for (int i = 1; i < n; i++)
{
int ai = sub[i];
int bi = n - sub[i];
if (min(ai, bi) < min(a, b) || max(ai, bi) < max(a, b))
continue;
if (ai >= a && bi >= b)
{
check[i] = 1;
check[0] = 2;
}
else
{
check[0] = 1;
check[i] = 2;
}
mark(0, num, a, b);
for (int j = 0; j < n; j++)
{
if (num[j] == 0)
num[j] = 3;
}
break;
}
return num;
}
else
{
vector<int> num(n, -1);
solve(num, 0, 1, a);
for (int i = 0; i < n; i++)
{
if (num[i] != -1)
continue;
int deg = 0;
for (auto& e : edge[i])
{
if (num[e] == -1)
deg++;
}
if (deg == 2)
continue;
solve(num, i, 2, b);
}
for (int i = 0; i < n; i++)
{
if (num[i] == -1)
num[i] = 3;
}
return num;
}
}
Compilation message (stderr)
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:99:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < p.size(); i++)
~~^~~~~~~~~~
split.cpp:105:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
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... |