이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n;
int t;
int pre[MAXN], low[MAXN];
int sub[MAXN];
vector<int> ar[MAXN];
int marcPA[MAXN];
vector<int> pa;
vector<pair<int, int> > comp[MAXN];
int cnt;
vector<int> ans;
void dfs(int cur, int pai);
void paint(int cur, int cor);
vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) {
n = N;
ans = vector<int> (n);
for(int i = 0; i < p.size(); i++){
ar[p[i]].push_back(q[i]);
ar[q[i]].push_back(p[i]);
}
dfs(0, 0);
int cor1;
int cor2;
int cor3;
int val1;
int val2;
int val3;
if(a <= b && a <= c){
cor1 = 1;
val1 = a;
if(b <= c) cor2 = 2, cor3 = 3, val2 = b, val3 = c;
else cor2 = 3, cor3 = 2, val2 = c, val3 = b;
}
else if(b <= a && b <= c){
cor1 = 2;
val1 = b;
if(a <= c) cor2 = 1, cor3 = 3, val2 = a, val3 = c;
else cor2 = 3, cor3 = 1, val2 = c, val3 = a;
}
else{
cor1 = 3;
val1 = c;
if(a <= b) cor2 = 1, cor3 = 2, val2 = a, val3 = b;
else cor2 = 2, cor3 = 1, val2 = b, val3 = a;
}
bool flag = true;
for(int i = 0; flag && i < pa.size(); i++){
int cur = pa[i];
sort(comp[cur].begin(), comp[cur].end());
if(comp[cur].back().first < val2) continue;
if(n - comp[cur].back().first < val1) continue;
ans[cur] = cor1;
ans[comp[cur].back().second] = cor2;
cnt = val1;
paint(cur, cor1);
cnt = val2;
paint(comp[cur].back().second, cor2);
flag = false;
}
for(int i = 0; flag && i < pa.size(); i++){
int cur = pa[i];
sort(comp[cur].begin(), comp[cur].end());
if(comp[cur].back().first < val1) continue;
if(n - comp[cur].back().first < val2) continue;
ans[cur] = cor2;
ans[comp[cur].back().second] = cor1;
cnt = val2;
paint(cur, cor2);
cnt = val1;
paint(comp[cur].back().second, cor1);
flag = false;
}
// if(flag) return ans;
if(flag){
cnt = val1;
paint(0, cor1);
for(int i = 0; i < n; i++){
if(ans[i] != 0) continue;
cnt = val2;
paint(i, cor2);
break;
}
}
for(int i = 0; i < n; i++)
if(ans[i] == 0) ans[i] = cor3;
return ans;
}
void dfs(int cur, int pai){
pre[cur] = low[cur] = ++t;
sub[cur] = 1;
for(int i = 0; i < ar[cur].size(); i++){
int viz = ar[cur][i];
if(viz == pai) continue;
if(pre[viz] != 0) low[cur] = min(low[cur], pre[viz]);
else{
dfs(viz, cur);
if(low[viz] >= pre[cur]){
if(cur != pai || sub[viz] != n - 1){
if(!marcPA[cur]){
pa.push_back(cur);
marcPA[cur] = 1;
}
comp[cur].push_back(make_pair(sub[viz], viz));
}
}
low[cur] = min(low[cur], low[viz]);
sub[cur] += sub[viz];
}
}
if(marcPA[cur]) comp[cur].push_back(make_pair(n - sub[cur], pai));
}
void paint(int cur, int cor){
if(cnt == 0) return;
ans[cur] = cor;
cnt--;
for(int i = 0; i < ar[cur].size(); i++){
int viz = ar[cur][i];
if(ans[viz] != 0) continue;
paint(viz, cor);
}
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i = 0; i < p.size(); i++){
| ~~^~~~~~~~~~
split.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i = 0; flag && i < pa.size(); i++){
| ~~^~~~~~~~~~~
split.cpp:74:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i = 0; flag && i < pa.size(); i++){
| ~~^~~~~~~~~~~
split.cpp:38:6: warning: variable 'val3' set but not used [-Wunused-but-set-variable]
38 | int val3;
| ^~~~
split.cpp: In function 'void dfs(int, int)':
split.cpp:110:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for(int i = 0; i < ar[cur].size(); i++){
| ~~^~~~~~~~~~~~~~~~
split.cpp: In function 'void paint(int, int)':
split.cpp:136:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
136 | for(int i = 0; i < ar[cur].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... |