이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Challenge: Accepted
#include <bits/stdc++.h>
#include "split.h"
#pragma GCC optimize("Ofast")
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 200005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
vector<int> adj[maxn], g[maxn]; //g is spanning tree
bool vis[maxn];
void dfs(int n) {
vis[n] = 1;
for (int v:adj[n]) {
if (!vis[v]) {
g[n].push_back(v);
g[v].push_back(n);
dfs(v);
}
}
}
int siz[maxn], pa[maxn];
void getsiz(int n, int par) {
siz[n] = 1;
pa[n] = par;
for (int v:g[n]) {
if (v != par) {
getsiz(v, n);
siz[n] += siz[v];
}
}
}
void getnode(int n, int par, vector<int> &vec, int s){
vec.push_back(n);
if (vec.size() >= s) return;
for (int v:g[n]) {
if (v != par) {
getnode(v, n, vec, s);
if (vec.size() >= s) return;
}
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> P, vector<int> Q) {
vector<int> ret(n, 0);
int m = P.size();
for (int i = 0;i < m;i++) {
adj[P[i]].push_back(Q[i]);
adj[Q[i]].push_back(P[i]);
}
dfs(0);
getsiz(0, -1);
pii ord[3] = {{a, 1}, {b, 2}, {c, 3}};
sort(ord, ord + 3);
for (int i = 0;i < 3;i++) debug(ord[i].ff, ord[i].ss);
int mi = ord[0].ff;
for (int i = 0;i < n;i++) {
if (mi <= siz[i] && siz[i] <= n - mi) {
for (int j = 0;j < n;j++) ret[j] = ord[2].ss;
vector<int> va, vb;
if (siz[i] * 2 <= n) {
getnode(i, pa[i], va, ord[0].ff);
getnode(pa[i], i, vb, ord[1].ff);
} else {
getnode(pa[i], i, va, ord[0].ff);
getnode(i, pa[i], vb, ord[1].ff);
}
for (int j:va) ret[j] = ord[0].ss;
for (int j:vb) ret[j] = ord[1].ss;
break;
}
}
return ret;
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'void getnode(int, int, std::vector<int>&, int)':
split.cpp:50:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
50 | if (vec.size() >= s) return;
| ~~~~~~~~~~~^~~~
split.cpp:54:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
54 | if (vec.size() >= s) return;
| ~~~~~~~~~~~^~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:14:20: warning: statement has no effect [-Wunused-value]
14 | #define debug(...) 0
| ^
split.cpp:70:28: note: in expansion of macro 'debug'
70 | for (int i = 0;i < 3;i++) debug(ord[i].ff, ord[i].ss);
| ^~~~~
# | 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... |