Submission #832117

#TimeUsernameProblemLanguageResultExecution timeMemory
832117maomao90Split the Attractions (IOI19_split)C++17
29 / 100
59 ms21020 KiB
// I can do all things through Christ who strengthens me // Philippians 4:13 #include "split.h" #include "bits/stdc++.h" using namespace std; #define REP(i, j, k) for (int i = j; i < (k); i++) #define RREP(i, j, k) for (int i = j; i >= (k); i--) template <class T> inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;} typedef long long ll; typedef long double ld; #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define SZ(x) (int) x.size() #define ALL(x) x.begin(), x.end() #define pb push_back typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vll; typedef tuple<int, int, int> iii; typedef vector<iii> viii; #ifndef DEBUG #define cerr if (0) cerr #endif const int INF = 1000000005; const ll LINF = 1000000000000000005; const int MAXN = 200005; int n, m, s[3], ss[3]; vi adj[MAXN]; vi ans; void mark(int u, int p, int &rem, int x) { if (rem == 0) { return; } ans[u] = x; rem--; for (int v : adj[u]) { if (v == p) { continue; } mark(v, u, rem, x); } } int sub[MAXN]; int pre[MAXN], ptr; bool dfs(int u, int p) { sub[u] = 1; pre[u] = ptr++; for (int v : adj[u]) { if (v == p) { continue; } if (pre[v] != -1) { continue; } if (dfs(v, u)) { return 1; } sub[u] += sub[v]; if (sub[v] >= s[ss[0]] && n - sub[v] >= s[ss[1]]) { mark(v, u, s[ss[0]], ss[0] + 1); mark(u, v, s[ss[1]], ss[1] + 1); return 1; } if (sub[v] >= s[ss[1]] && n - sub[v] >= s[ss[0]]) { mark(v, u, s[ss[1]], ss[1] + 1); mark(u, v, s[ss[0]], ss[0] + 1); return 1; } } return 0; } vi find_split(int n, int a, int b, int c, vi p, vi q) { ::n = n; s[0] = a; s[1] = b; s[2] = c; iota(ss, ss + 3, 0); sort(ss, ss + 3, [&] (int l, int r) { return s[l] < s[r]; }); m = SZ(p); REP (i, 0, m) { adj[p[i]].pb(q[i]); adj[q[i]].pb(p[i]); } ans = vi(n, ss[2] + 1); memset(pre, -1, sizeof pre); if (!dfs(0, -1)) { ans = vi(n, 0); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...