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 <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<bool> vis;
int n, m;
vector<int> ord, k, ans;
void dfs (int u) {
vis[u] = 1;
for (int v : adj[u]) {
if (!vis[v]) {
dfs(v);
}
}
ord.push_back(u);
}
void go (int i) {
while (k[i]) {
--k[i];
ans[ord.back()] = i + 1;
ord.pop_back();
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
::n = n;
k = {a, b, c};
m = p.size();
adj.resize(n);
ans.resize(n);
vis.resize(n);
for (int i = 0; i < m; ++i) {
adj[p[i]].push_back(q[i]);
adj[q[i]].push_back(p[i]);
}
array<int, 2> P[n];
for (int i = 0; i < n; ++i) {
P[i] = {(int)adj[i].size(), i};
}
sort(P, P + n);
dfs(P[0][1]);
for (int i = 0; i < 3; ++i) {
go(i);
}
return ans;
}
# | 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... |