#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];
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])
{
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 : g[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;
}
Compilation message
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int i = 0; i < p.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
5076 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5204 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
ok, correct split |
2 |
Incorrect |
46 ms |
10084 KB |
invalid split: #1=19999, #2=40000, #3=40001 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5076 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
5076 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |