QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#162988 | #7121. Beech Tree | zhouhuanyi# | 9 | 1ms | 6220kb | C++14 | 2.1kb | 2023-09-03 18:28:32 | 2024-04-28 06:55:15 |
Judging History
answer
#include"beechtree.h"
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<bitset>
#define N 2000
#define SM 200
using namespace std;
int n,length,cl[N+1],fa[N+1],tong[N+1],cnt[N+1],num[N+1];
vector<int>E[N+1];
bool used[N+1][N+1];
bitset<SM+1>B[N+1];
bitset<SM+1>B2[N+1];
void dfs(int x)
{
tong[++length]=x;
for (int i=0;i<E[x].size();++i) dfs(E[x][i]);
return;
}
bool cmp(int x,int y)
{
return E[x].size()>E[y].size();
}
void adder(int x,int y)
{
used[x][y]=B[x][y]=B2[y][x]=1;
bitset<SM+1>res;
bitset<SM+1>rst;
int ps;
while (1)
{
rst=B[x],rst.flip(),res=B[y]&rst,ps=res._Find_first();
if (res._Find_first()!=res.size()) adder(x,ps);
else break;
}
while (1)
{
rst=B2[y],rst.flip(),res=B2[x]&rst,ps=res._Find_first();
if (res._Find_first()!=res.size()) adder(ps,y);
else break;
}
if (fa[x]&&fa[y]&&cl[tong[x]]==cl[tong[y]]) adder(fa[x],fa[y]);
return;
}
vector<int>beechtree(int SN,int M,vector<int>P,vector<int>C)
{
bool op,opt;
vector<int>p(SN);
n=SN;
for (int i=1;i<n;++i) E[P[i]].push_back(i),cl[i]=C[i];
for (int i=0;i<n;++i)
{
length=0,dfs(i),sort(tong+1,tong+length+1,cmp);
for (int j=0;j<M;++j) cnt[j]=0;
for (int j=1;j<=length;++j)
if (tong[j]!=i)
cnt[cl[tong[j]]]++;
opt=1;
for (int j=0;j<M;++j)
for (int k=1;k<=cnt[j];++k)
{
op=0;
for (int t=0;t<E[tong[k]].size();++t) op|=(C[E[tong[k]][t]]==j);
opt&=op;
}
if (opt)
{
for (int j=1;j<=length;++j)
for (int k=1;k<=length;++k)
used[j][k]=B[j][k]=B2[j][k]=0;
for (int j=1;j<=length;++j) num[tong[j]]=j;
for (int j=1;j<=length;++j)
{
if (tong[j]!=i)
{
fa[j]=num[P[tong[j]]];
if (!used[num[P[tong[j]]]][j]) adder(num[P[tong[j]]],j);
}
else fa[j]=0;
}
for (int j=1;j<=length;++j)
for (int k=j+1;k<=length;++k)
if (E[tong[j]].size()>E[tong[k]].size()&&!used[j][k])
adder(j,k);
for (int j=1;j<=length;++j)
if (used[j][j])
opt=0;
if (opt) p[i]=1;
}
}
return p;
}
詳細信息
Subtask #1:
score: 9
Accepted
Test #1:
score: 9
Accepted
time: 1ms
memory: 4156kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 8 500 -1 0 1 2 3 4 5 6 0 281 281 281 281 281 281 281
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 1 1 1 1 1 1 1 1
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 8 500 -1 0 1 2 3 4 5 6 0 11 169 169 169 169 169 169
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 0 1 1 1 1 1 1 1
result:
ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 8 500 -1 0 1 2 3 4 5 6 0 324 324 492 324 324 324 324
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 0 0 0 1 1 1 1 1
result:
ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 8 500 -1 0 1 2 3 4 5 6 0 216 220 387 371 53 34 188
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 0 0 0 0 0 0 1 1
result:
ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 7 500 -1 0 0 0 1 1 2 0 357 147 147 20 147 20
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 0 1 1 1 1 1 1
result:
ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 4 500 -1 0 0 0 0 267 210 278
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 1 1 1 1
result:
ok
Test #7:
score: 0
Accepted
time: 1ms
memory: 6220kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 7 500 -1 0 0 0 1 2 3 0 250 140 214 250 250 140
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 0 1 1 1 1 1 1
result:
ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 5928kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 8 500 -1 0 0 0 1 1 3 3 0 40 205 455 455 36 36 455
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 0 1 1 1 1 1 1 1
result:
ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 7 500 -1 0 0 1 1 1 2 0 181 33 33 181 201 33
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 0 1 1 1 1 1 1
result:
ok
Test #10:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 5 500 -1 0 0 1 2 0 162 281 162 162
output:
p89vHUOQJ7iyHtdrgGXzKx8iRtXLL6wH OK 1 1 1 1 1
result:
ok
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 200000 200000 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #25:
score: 0
Runtime Error
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 103965 200000 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #48:
score: 0
Runtime Error
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 199979 200000 -1 0 1 1 1 1 1 1 1 1 1 1 11 11 1 11 11 11 11 11 11 11 0 22 23 23 23 23 23 23 23 23 23 23 33 22 35 36 36 36 36 36 36 36 36 38 38 38 35 48 49 49 49 49 49 49 49 53 53 48 59 60 60 60 60 60 59 66 67 67 67 67 67 67 67 67 67 67 73 71 66 80 81 81 81 81 81 81 81...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #54:
score: 0
Time Limit Exceeded
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 200 500 -1 0 0 1 1 2 3 4 5 6 2 7 0 8 9 10 11 12 13 14 1 15 3 16 17 2 18 19 20 4 5 21 22 23 24 25 26 27 28 29 6 30 31 3 32 33 34 35 36 37 7 8 9 38 10 39 11 40 41 12 13 14 4 42 43 44 45 46 5 47 6 48 15 49 50 51 16 52 53 7 54 17 55 56 57 8 9 18 58 59 60 61 19 62 63 64 2...
output:
result:
Subtask #6:
score: 0
Time Limit Exceeded
Test #65:
score: 0
Time Limit Exceeded
input:
j2DRV0nYbs0y1xUYUGaiqtOKUU9vM9zi 2000 2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 ...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%