This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "split.h"
namespace TEST1 {
bool check(int n, int A, int B, int C, VI P, VI Q) {
int m = P.size();
VI degree(n);
rep(i, m) {
degree[P[i]]++;
degree[Q[i]]++;
}
for (int x : degree) if (x > 2) return false;
return true;
}
VI find_split(int n, int A, int B, int C, VI U, VI V) {
VVI gp(n);
int m = U.size();
rep(i, m) {
gp[U[i]].pb(V[i]);
gp[V[i]].pb(U[i]);
}
int st = -1;
int nd = -1;
rep(u, n) if (gp[u].size() == 1) {
if (st == -1) st = u;
else nd = u;
}
if (st == -1) {
st = 0;
nd = gp[0].back();
gp[0].pop_back();
}
VI ans(n, 3);
auto color = [&](int u, int cnt, int col) {
int p = -1;
while (cnt--) {
ans[u] = col;
for (int v : gp[u]) if (v != p) {
p = u;
u = v;
break;
}
}
};
color(st, A, 1);
color(nd, B, 2);
return ans;
}
};
namespace TEST2 {
int n;
VVI gp;
VI vis;
VI ans;
void dfs(int u, int cnt) {
if (cnt == 0) return;
ans[u] = 2;
vis[u] = true;
for (int v : gp[u]) if (!vis[v]) {
dfs(v, cnt-1);
}
}
VI find_split(int N, int A, int B, int C, VI U, VI V) {
n = N;
gp = VVI(n);
int m = U.size();
rep(i, m) {
gp[U[i]].pb(V[i]);
gp[V[i]].pb(U[i]);
}
vis = VI(n);
ans = VI(n, 3);
dfs(0, B);
rep(u, n) if (ans[u] == 3) {
ans[u] = 1;
break;
}
return ans;
}
};
VI find_split(int n, int A, int B, int C, VI P, VI Q) {
if (TEST1::check(n, A, B, C, P, Q)) return TEST1::find_split(n, A, B, C, P, Q);
if (A == 1) return TEST2::find_split(n, A, B, C, P, Q);
return {};
}
# | 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... |