QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#350076 | #8212. Football in Osijek | ucup-team1525# | WA | 3ms | 27404kb | C++17 | 2.1kb | 2024-03-10 13:48:47 | 2024-03-10 13:48:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e5;
int n;
int fa[N+5];
int bl[N+5],cl[N+5];
bool vis[N+5],in[N+5];
int st[N+5],sts;
void dfs(int u){
if(!vis[u]){
vis[u]=1; in[u]=1;
st[++sts]=u;
dfs(fa[u]);
sts--; in[u]=0;
}
else if(in[u]){
for(int j=sts;;j--){
cl[u]++;
bl[st[j]]=u;
if(st[j]==u) break;
}
}
}
vector<int> e[N+5];
int val[N+5],son[N+5];
void dfs2(int u){
for(auto v:e[u]){
dfs2(v);
if(val[v]>val[u]){
val[u]=val[v];
son[u]=v;
}
}
val[u]++;
}
struct Que{
int u,val;
Que(int u=0,int val=0):u(u),val(val){}
bool operator < (const Que t) const{
return val<t.val;
}
};
priority_queue<Que> q;
vector<int> e2[N+5];
void get(int u){
for(int i=u;son[i];i=son[i])
for(auto v:e[i])
if(v!=son[i]){
e2[u].push_back(v);
get(v);
}
}
int cov[N+5];
int ans[N+5];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&fa[i]);
for(int i=1;i<=n;i++)
if(!vis[i]) dfs(i);
for(int i=1;i<=n;i++)
if(!bl[i]){
if(!bl[fa[i]]){
e[fa[i]].push_back(i);
}
else e[bl[fa[i]]].push_back(i);
}
int mx=0;
for(int i=1;i<=n;i++)
if(bl[i]==i){
dfs2(i);
val[i]+=cl[i]-1;
get(i);
q.push(Que(i,val[i]));
cov[cl[i]]++; cov[val[i]+1]--;
mx=max(mx,val[i]);
// printf("%d %d\n",cl[i],val[i]+1);
}
for(int i=1;i<=mx;i++){
cov[i]+=cov[i-1];
ans[i]=1;
if(cov[i]) ans[i]=0;
printf("%d ",ans[i]);
}
int sum=0,k=-1;
for(int i=mx+1;i<=n;i++){
while(i>sum){
Que top=q.top(); q.pop();
sum+=top.val; k++;
for(auto v:e[top.u])
q.push(Que(v,val[v]));
}
printf("%d ",k);
}
puts("");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 27404kb
input:
5 2 3 1 3 5
output:
0 1 0 0 1
result:
ok 5 number(s): "0 1 0 0 1"
Test #2:
score: 0
Accepted
time: 3ms
memory: 27348kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 3ms
memory: 27368kb
input:
2 2 2
output:
0 0
result:
ok 2 number(s): "0 0"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 27232kb
input:
10 4 7 2 8 4 3 4 9 7 3
output:
1 1 1 0 0 0 0 1 1 1
result:
wrong answer 9th numbers differ - expected: '2', found: '1'