#include <bits/stdc++.h>
#define f first
#define s second
#define ent '\n'
using namespace std;
typedef long long ll;
const int mx=2e5+12;
pair<int,int> fup[mx];
vector<int> g[mx];
set<int> e[mx];
int Ans[mx];
int par[mx];
int tin[mx];
int ver[mx];
int sz[mx];
int pos[]={1,2,3};
int timer;
void calc(int v){
sz[v]=1;
for(int to:g[v]){
if(sz[to]>0)continue;
calc(to);
par[to]=v;
e[v].insert(to);
sz[v]+=sz[to];
}
}
void dfs(int v,int p){
tin[v]=fup[v].f=++timer;
fup[v].s=v;
ver[tin[v]]=v;
for(int to:g[v]){
if(to==p)continue;
if(tin[to]>0){
fup[v]=min(fup[v],{tin[to],v});
assert(0);
}
else{
dfs(to,v);
fup[v]=min(fup[v],fup[to]);
}
}
}
void get(int v,int p,int &cnt,int t){
if(!cnt)return;
Ans[v]=pos[t];
cnt--;
if(!cnt)return;
for(int to:e[v]){
get(to,v,cnt,t);
}
}
std::vector<int> find_split(int n, int a, int b, int c, std::vector<int> p, std::vector<int> q){
for(int i=0;i<p.size();i++){
g[p[i]].push_back(q[i]);
g[q[i]].push_back(p[i]);
}
if(a>b){
swap(a,b);
swap(pos[0],pos[1]);
}
if(a>c){
swap(a,c);
swap(pos[0],pos[2]);
}
if(b>c){
swap(b,c);
swap(pos[1],pos[2]);
}
int A=a,B=b,C=c;
calc(0);
dfs(1,0);
int v=-1;
for(int i=1;i<n;i++){
if(sz[i]<a)continue;
bool ok=1;
for(int to:e[i]){
if(sz[to]>=a)ok=0;
}
if(ok){
v=i;
break;
}
}
vector<int> ans(n);
if(v<0)return ans;
bool bad=0;
vector<int> edg;
for(int to:e[v]){
edg.push_back(to);
}
for(int to:edg){
if(sz[v]-sz[to]<a){
break;
}
if(fup[to].f<tin[v]){
sz[v]-=sz[to];
e[v].erase(to);
e[ver[fup[to].f]].insert(fup[to].s);
}
}
e[par[v]].erase(v);
if(sz[v]>=a && n-sz[v]>=b){
get(v,0,a,0);
get(0,0,b,1);
for(int i=0;i<n;i++){
ans[i]=Ans[i];
if(!ans[i])ans[i]=pos[2];
}
}
else if(sz[v]>=b && n-sz[v]>=a){
get(v,0,b,1);
get(0,0,a,0);
for(int i=0;i<n;i++){
ans[i]=Ans[i];
if(!ans[i])ans[i]=pos[2];
}
}
return ans;
}
Compilation message
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:60:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
split.cpp:76:6: warning: unused variable 'A' [-Wunused-variable]
76 | int A=a,B=b,C=c;
| ^
split.cpp:76:10: warning: unused variable 'B' [-Wunused-variable]
76 | int A=a,B=b,C=c;
| ^
split.cpp:76:14: warning: unused variable 'C' [-Wunused-variable]
76 | int A=a,B=b,C=c;
| ^
split.cpp:93:7: warning: unused variable 'bad' [-Wunused-variable]
93 | bool bad=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18780 KB |
ok, correct split |
2 |
Runtime error |
23 ms |
37980 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18776 KB |
ok, correct split |
2 |
Runtime error |
20 ms |
37980 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
18776 KB |
ok, correct split |
2 |
Correct |
77 ms |
27988 KB |
ok, correct split |
3 |
Correct |
28 ms |
22876 KB |
ok, correct split |
4 |
Correct |
4 ms |
18780 KB |
ok, correct split |
5 |
Correct |
101 ms |
30800 KB |
ok, correct split |
6 |
Correct |
90 ms |
31292 KB |
ok, correct split |
7 |
Correct |
109 ms |
31568 KB |
ok, correct split |
8 |
Correct |
76 ms |
31316 KB |
ok, correct split |
9 |
Incorrect |
121 ms |
30804 KB |
invalid split: #1=30000, #2=30000, #3=40000 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
27 ms |
37976 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18780 KB |
ok, correct split |
2 |
Runtime error |
23 ms |
37980 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |