제출 #425098

#제출 시각아이디문제언어결과실행 시간메모리
425098alishahali1382Split the Attractions (IOI19_split)C++14
7 / 100
570 ms1048580 KiB
#include "split.h" #include<bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define debug(x) {cerr<<#x<<"="<<x<<"\n";} #define debug2(x, y) {cerr<<"{"<<#x<<", "<<#y<<"}={"<<x<<", "<<y<<"}\n";} #define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";} #define debugv(abcd) {cerr<<#abcd<<": ";for (auto dcba:abcd) cerr<<dcba<<", ";cerr<<"\n";} #define pb push_back #define SZ(x) ((int)x.size()) #define all(x) x.begin(), x.end() const int inf=1000001000; // 1e9 const ll INF=10000000010000000; // 1e16 const int mod=1000000007; const int MAXN=100010; vector<pair<int, char>> perm; int n, m, k, a, b, c, u, v, t, x, y, solved; int mark[MAXN], sz[MAXN], par[MAXN]; vector<int> G[MAXN]; vector<int> out; vector<int> topol; void dfs1(int node){ topol.pb(node); mark[node]=1; for (int v:G[node]) if (!mark[v]) dfs1(v); } int dfs2(int node){ for (int v:G[node]) if (v!=par[node]){ par[v]=node; sz[node]+=dfs2(v); } return ++sz[node]; } vector<int> find_split(int _n, int _a, int _b, int _c, vector<int> _p, vector<int> _q){ n=_n; out.resize(n, 0); a=_a; b=_b; c=_c; for (int i=0; i<n-1/*SZ(_p)*/; i++){ int u=_p[i], v=_q[i]; G[u].pb(v); G[v].pb(u); } perm.pb({a, 'a'}); perm.pb({b, 'b'}); perm.pb({c, 'c'}); sort(all(perm)); a=perm[0].first; b=perm[1].first; c=perm[2].first; // ---------------- dfs2(0); for (int i=1; i<n && !solved; i++){ if (sz[i]>=a && n-sz[i]>=b){ mark[i]=mark[par[i]]=1; dfs1(par[i]); for (int j=0; j<b; j++) out[topol[j]]=2; topol.clear(); dfs1(i); for (int j=0; j<a; j++) out[topol[j]]=1; topol.clear(); solved=1; break ; } if (sz[i]>=b && n-sz[i]>=a){ mark[i]=mark[par[i]]=1; dfs1(par[i]); for (int j=0; j<a; j++) out[topol[j]]=2; topol.clear(); dfs1(i); for (int j=0; j<b; j++) out[topol[j]]=1; solved=1; break ; } } // ---------------- if (!solved) return out; debugv(out) for (int i=0; i<n; i++){ if (!out[i]) out[i]=3; /* int j=0; while (perm[j].second-'a'+1!=out[i]) j++; out[i]=j+1;*/ out[i]=perm[out[i]-1].second-'a'+1; } return out; }
#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...