# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
794629 | Pablo_No | Split the Attractions (IOI19_split) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1e5+5;
int used[N];
int gn, ga, gb, gc;
vector<int> g[N];
vector<int> g2[N];
int pv, pu, pw;
int dfs(int v, int p)
{
used[v] = true;
vector<pair<int, int>> sts;
int ts = 1;
for(int u : g[v]) if(!used[u])
{
g2[u].push_back(v);
g2[v].push_back(u);
int x = dfs(u, v);
sts.push_back({x, u});
ts += x;
}
if(p != -1)
sts.push_back({gn-ts, p});
sort(sts.begin(), sts.end());
auto pt = lower_bound(sts.begin(), sts.end(), pair<int, int>(ga, -1));
if(pt != sts.end() && (gn-pt->first) >= gb)
{
pv = v;
pu = pt->second;
pw = 2;
}
pt = lower_bound(sts.begin(), sts.end(), pair<int, int>(gb, -1));
if(pt != sts.end() && (gn-pt->first) >= ga)
{
pv = v;
pu = pt->second;
pw = 1;
}
return ts;
}
vector<int> res;
int used2[N];
int rem = 0;
void dfs2(int v, int c)
{
used2[v] = true;
if(rem)
{
res[v-1] = c;
rem--;
}
for(int u : g2[v]) if(!used2[u])
dfs2(u, c);
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
res.assign(n, 3);
vector<int> cs(3);
cs[1] = a;
cs[2] = b;
gn = n;
ga = a, gb = b, gc = c;
for(int i = 0; i < p.size(); i++)
{
g[p[i]].push_back(q[i]);
g[q[i]].push_back(p[i]);
}
pv = -1;
dfs(1, -1);
if(pv == -1)
{
res.assign(n, 0);
return res;
}
used2[pu] = true;
rem = cs[pw];
dfs2(pv, pw);
used2[pu] = false;
rem = cs[3-pw];
dfs2(pu, 3-pw);
return res;
}
////////////////////
#include <cstdio>
#include <cassert>
using namespace std;
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;
}