이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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(b, 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 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... |