제출 #767036

#제출 시각아이디문제언어결과실행 시간메모리
767036khshgSplit the Attractions (IOI19_split)C++14
7 / 100
538 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>; #define mp make_pair #define ff first #define ss second #define ar array template<class T> using V = vector<T>; using vi = V<int>; using vb = V<bool>; using vl = V<ll>; using vd = V<ld>; using vs = V<str>; using vpi = V<pi>; using vpl = V<pl>; using vpd = V<pd>; #define sz(x) (int)((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define pb push_back #define eb emplace_back #define ft front() #define bk back() #define lb lower_bound #define ub upper_bound #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for(int i = (b) - 1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define rep(a) F0R(_, a) #define trav(a, x) for(auto& a : x) template<class T> bool ckmin(T& a, const T& b) { return (b < a ? a = b, 1 : 0); } template<class T> bool ckmax(T& a, const T& b) { return (b > a ? a = b, 1 : 0); } V<vi> adj; int bfs(int s) { vi q; q.pb(s); vi dis(sz(adj), 0x3f3f3f3f); dis[s] = 0; int fn = s; while(sz(q)) { int cur = q.bk; q.pop_back(); if(dis[fn] < dis[cur]) fn = cur; trav(u, adj[cur]) { if(ckmin(dis[u], dis[cur] + 1)) { q.pb(u); } } } return fn; } void find_path(int s, int p, int g, vi& path) { path.eb(s); if(s == g) return; trav(u, adj[s]) { if(u == p) continue; find_path(u, s, g, path); if(path.bk == g) break; } if(path.bk == g) return; path.pop_back(); } vi ans; void color(int s, int& cnt, int c) { if(!cnt) return; --cnt; ans[s] = c; trav(u, adj[s]) { if(!cnt) break; if(ans[u] == 0) color(u, cnt, c); } } vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> Q) { adj.rsz(N); ans.rsz(N); int M = sz(p); F0R(i, M) { adj[p[i]].pb(Q[i]); adj[Q[i]].pb(p[i]); } int nd1 = bfs(0); int nd2 = bfs(nd1); int mn = min({a, b, c}); int mn2 = a + b + c - mn - max({a, b, c}); int mncolor = (a == mn ? 1 : (b == mn ? 2 : 3)); int mn2color = (a == mn2 && mncolor != 1 ? 1 : (b == mn2 && mncolor != 2 ? 2 : 3)); vi path; find_path(nd1, -1, nd2, path); int i = 0; vi q; while(mn) { if(q.empty()) q.pb(path[i]); int cur = q.bk; q.pop_back(); ans[cur] = mncolor; --mn; if(cur == path[i]) { ++i; if(i == sz(path)) return ans;//vi(N, 0); } trav(u, adj[cur]) { if(u == path[i]) continue; if(ans[u] == 0) q.pb(u); } } color(nd2, mn2, mn2color); F0R(i, N) { if(ans[i] == 0) { ans[i] = 6 - mncolor - mn2color;//; } } return ans; } /* int main() { int n, m, a, b, c; assert(5 == scanf("%d%d%d%d%d", &n, &m, &a, &b, &c)); vector<int> p(m), q(m); for (int i=0; i<m; i++) assert(2 == scanf("%d%d", &p[i], &q[i])); fclose(stdin); vector<int> result = find_split(n, a, b, c, p, q); for (int i=0; i<(int)result.size(); i++) printf("%s%d", ((i>0)?" ":""), result[i]); printf("\n"); fclose(stdout); return 0; }*/
#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...