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 <bits/stdc++.h>
#include "split.h"
using namespace std;
typedef long long ll;
vector<vector<ll>> adj;
vector<vector<ll>> adj1;
vector<bool> vst;
vector<ll> subSize;
vector<ll> parent;
vector<int> res;
ll dfs(ll node, ll par) {
vst[node] = true;
parent[node] = par == -1 ? node : par;
ll sum = 1;
for (auto &e : adj[node]) {
if (!vst[e]) {
sum += dfs(e, node);
adj1[node].push_back(e);
adj1[e].push_back(node);
}
}
subSize[node] = sum;
return sum;
}
int subG, subGVal;
void dfs2(ll node) {
if (subGVal-- > 0) {
res[node] = subG;
}
else {
return;
}
vst[node] = true;
for (auto &e : adj1[node]) {
if (e == parent[node]) continue;
dfs2(e);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
/*if (a == 1) {
int m = p.size();
vector<int> res(n);
adj = vector<vector<ll>>(n);
for (int i = 0; i < m; i++) {
adj[p[i]].push_back(q[i]);
adj[q[i]].push_back(p[i]);
}
ll lowDeg = 0, deg = n;
for (int i = 0; i < n; i++) {
if (adj[i].size() < deg) {
lowDeg = i;
deg = adj[i].size();
}
}
queue<ll> qu;
qu.push(lowDeg);
while (!qu.empty()) {
ll node = qu.front(); qu.pop();
if (c) { res[node] = 3; c--; }
else if (b) { res[node] = 2; b--; }
else { res[node] = 1; }
for (auto &e : adj[node]) {
if (!res[e]) { qu.push(e); res[e] = 5; }
}
}
return res;
}*/
for (int t = 0; t < n && (q.size() != n-1 || t == 0); t++) {
int m = p.size();
res = vector<int>(n);
adj = vector<vector<ll>>(n);
adj1 = vector<vector<ll>>(n);
parent = vector<ll>(n);
subSize = vector<ll>(n);
for (int i = 0; i < m; i++) {
adj[p[i]].push_back(q[i]);
adj[q[i]].push_back(p[i]);
}
vst = vector<bool>(n);
subSize[t] = dfs(t, -1);
bool possible = 0;
ll id = 0;
ll low = min({a, b, c}), high = n - min({a, b, c});
for (int i = 0; i < n; i++) {
if (subSize[i] >= low && subSize[i] <= high) { possible = 1; id = i; }
}
if (!possible) {
continue;
}
vst = vector<bool>(n);
vector<pair<ll, ll>> g;
g.push_back({a, 1});
g.push_back({b, 2});
g.push_back({c, 3});
sort(g.begin(), g.end());
subG = subSize[id] < n/2 ? g[0].second : g[1].second;
subGVal = subSize[id] < n/2 ? g[0].first : g[1].first;
dfs2(id);
ll pr = parent[id];
subG = subSize[id] >= n/2 ? g[0].second : g[1].second;
subGVal = subSize[id] >= n/2 ? g[0].first : g[1].first;
adj1 = vector<vector<ll>>(n);
dfs(id, -1);
dfs2(pr);
for (auto &e : res) {
if (!e) e = g[2].second;
}
return res;
}
return vector<int>(n);
}
Compilation message (stderr)
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:77:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
77 | for (int t = 0; t < n && (q.size() != n-1 || t == 0); t++) {
| ~~~~~~~~~^~~~~~
# | 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... |