#include "split.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<int>> graph;
vector<bool> visited;
vector<int> res;
int A = 0, B = 0, C = 0;
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
res.assign(n, 0);
graph.resize(n);
visited.assign(n, 0);
for (int i = 0; i < p.size(); ++i) {
graph[p[i]].push_back(q[i]);
graph[q[i]].push_back(p[i]);
}
vector<vector<int>> depth;
queue<pair<int, int>> Q;
Q.push({0, 0});
visited[0] = 1;
depth.push_back({});
depth[0].push_back(0);
while (!Q.empty()) {
auto [u, d] = Q.front(); Q.pop();
for (int v: graph[u]) {
if (visited[v]) continue;
if (d >= depth.size()) depth.push_back({});
depth[d].push_back(v);
visited[v] = 1;
Q.push({v, d + 1});
}
}
visited.assign(n, 0);
for (int i = depth.size() - 1; i >= 0; --i) {
for (int u: depth[i]) {
cout << u << " ";
if (A < a) {
visited[u] = 1;
A++;
res[u] = 1;
}
}
cout << "\n";
}
for (int u = 0; u < n; ++u) {
if (!visited[u]) {
if (B < b) {
B++;
res[u] = 2;
}
else if (C < c) {
C++;
res[u] = 3;
}
}
}
return res;
}
# | 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... |