이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int mxN = 1e5, INF = 1e9;
vector<int> adj[mxN], t[mxN], cg[mxN], ans;
int n, seen1[mxN], bst_mx=INF, bst_u, bst_v, dsu[mxN], sz[mxN];
int f(int x) {return dsu[x] != x ? dsu[x] = f(dsu[x]) : x;}
int dfs1(int u, int p) {
seen1[u] = 1;
int sm = 1, mx = 0, bv = 0;
for (int v: adj[u]) {
if (!seen1[v]) {
t[u].push_back(v);
t[v].push_back(u);
int res = dfs1(v, u);
sm += res;
if (res > mx) {
bv = v;
mx = res;
}
}
}
int res = n-sm;
if (res > mx) {
bv = p;
mx = res;
}
if (mx < bst_mx) {
bst_mx = mx;
bst_u = u;
bst_v = bv;
}
return sm;
}
void dfs2(int u, pii &cc, vector<int>* g) {
if (cc.first) {
cc.first--;
ans[u] = cc.second;
} else return;
for (int v: g[u]) if (!ans[v]) {
dfs2(v, cc, g);
}
}
void merge(int a, int b) {
cg[a].push_back(b);
cg[b].push_back(a);
a = f(a), b = f(b);
if (a != b) {
if (sz[b] > sz[a]) swap(a,b);
dsu[b] = a;
sz[a] += sz[b];
}
}
vector<int> find_split(int _n, int a, int b, int c, vector<int> p, vector<int> q) {
n = _n;
pii ccs[3] = {{a,1},{b,2},{c,3}};
sort(ccs, ccs+3);
ans.resize(n);
for (int i = 0; i < p.size(); ++i) {
adj[p[i]].push_back(q[i]);
adj[q[i]].push_back(p[i]);
}
dfs1(0,0);
if (bst_mx >= ccs[0].first) {
ans[bst_u] = ccs[1].second;
dfs2(bst_v, ccs[0], t);
dfs2(bst_u, ccs[1], t);
} else {
bool valid = 0;
iota(dsu, dsu+n, 0);
fill(sz, sz+n, 1);
for (int u = 0; u < n; ++u) for (int v: t[u]) {
if (u != bst_u && v != bst_u) merge(u, v);
}
for (int u = 0; u < n && !valid; ++u) for (int v: adj[u]) {
if (u != bst_u && v != bst_u) merge(u, v);
if (sz[f(u)] >= ccs[0].first) {
valid = 1;
dfs2(u, ccs[0], cg);
dfs2(bst_u, ccs[1], t);
break;
}
}
if (!valid) return ans;
}
for (int i = 0; i < n; ++i) if (!ans[i]) ans[i] = ccs[2].second;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:65:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i = 0; i < p.size(); ++i) {
| ~~^~~~~~~~~~
# | 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... |