이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include <bits/stdc++.h>
#define int long long
#define inf ((int)1e18)
const int N = 100000;
using namespace std;
vector<int32_t> find_split(int32_t n, int32_t a, int32_t b, int32_t c, vector<int32_t> p, vector<int32_t> q) {
vector <int32_t> sub(n), ans(n);
vector <vector<int> > adj(n);
int m = p.size();
vector <pair<int, int> > fuck = {{a, 1}, {b, 2}, {c, 3}};
for(int i = 0; i < n - 1; i++) {
int a = p[i], b = q[i];
adj[a].push_back(b);
adj[b].push_back(a);
}
int size = 0;
auto taguntil = [&](int node, int ata, int tag, auto&& dfs) -> void {
size--;
ans[node] = tag;
for(auto it:adj[node]) {
if(it == ata) continue;
if(size) dfs(it, node, tag, dfs);
}
};
auto dfs = [&](int node, int ata, auto&& dfs) -> bool {
// cout << node << " " << ata << endl;
sub[node] = 1;
for(auto it:adj[node]) {
if(it == ata) continue;
if(dfs(it, node, dfs)) {
return true;
}
sub[node] += sub[it];
}
if(sub[node] == fuck[0].first) {
size = fuck[0].first;
taguntil(node, ata, fuck[0].second, taguntil);
size = fuck[1].first;
taguntil(ata, node, fuck[1].second, taguntil);
for(auto &it:ans) if(it == 0) it = fuck[2].second;
return true;
}
if(n - sub[node] == fuck[0].first) {
size = fuck[0].first;
taguntil(ata, node, fuck[0].second, taguntil);
size = fuck[1].first;
taguntil(node, ata, fuck[1].second, taguntil);
for(auto &it:ans) if(it == 0) it = fuck[2].second;
return true;
}
return false;
};
if(dfs(0, 0, dfs)) return ans;
swap(fuck[0], fuck[1]);
if(dfs(0, 0, dfs)) return ans;
swap(fuck[0], fuck[2]);
if(dfs(0, 0, dfs)) return ans;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'std::vector<int> find_split(int32_t, int32_t, int32_t, int32_t, std::vector<int>, std::vector<int>)':
split.cpp:11:6: warning: unused variable 'm' [-Wunused-variable]
11 | int m = p.size();
| ^
# | 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... |