#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N=1e5+2;
vector<int> ma[N],ans;
bool vis[N];
int n;
int sz[N],up[N],h[N];
pair<int,int> comp[3];
bool f=0;
void df1(int x,int p)
{
if(comp[p].first==0)
return;
vis[x]=1;
if(comp[p].first>0)
{
cout<<"Marked "<<x<<' '<<comp[p].first<<endl;
ans[x]=comp[p].second;
comp[p].first--;
}
for(int y:ma[x])
if(!vis[y] and ans[y]==comp[2].second)
df1(y,p);
}
void dfs(int x,int q=-1)
{
vis[x]=1;
sz[x]=1;
bool p=1;
vector<int> c;
for(int y:ma[x])
{
if(!vis[y])
{
up[y]=h[y]=h[x]+1;
c.push_back(y);
dfs(y,x);
p&=(sz[y]<comp[0].first);
sz[x]+=sz[y];
up[x]=min(up[x],up[y]);
}
else
up[x]=min(up[x],h[y]);
}
if(p and !f and sz[x]>=comp[0].first)
{
int P1=sz[x];
int P2=n-P1;
vector<int> b;
for(int y:c)
{
if(up[y]<h[x] and (P1-sz[y])>=comp[0].first)
P1-=sz[y],P2+=sz[y];
else
b.push_back(y);
}
if(P2>=comp[1].first)
{
for(int i=0;i<n;i++)
vis[i]=0;
vis[x]=1;
ans[x]=comp[0].second;
comp[0].first--;
for(auto i:b)
df1(i,0);
for(int i=0;i<n;i++)
if(ans[i]!=comp[0].second)
{
df1(i,1);
break;
}
f=1;
}
}
}
vector<int> find_split(int n1, int a, int b, int c, vector<int> p, vector<int> q)
{
n=n1;
comp[0]={a,1},comp[1]={b,2},comp[2]={c,3};
sort(comp,comp+3);
int m=p.size();
for(int i=0;i<m;i++)
ma[p[i]].push_back(q[i]),ma[q[i]].push_back(p[i]);
ans.resize(n,comp[2].second);
dfs(0);
if(!f)
for(int i=0;i<n;i++)
ans[i]=0;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3672 KB |
secret mismatch |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3676 KB |
secret mismatch |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3672 KB |
secret mismatch |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3676 KB |
secret mismatch |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3672 KB |
secret mismatch |
2 |
Halted |
0 ms |
0 KB |
- |