QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#210708 | #6638. Treelection | xia_mc | WA | 104ms | 5836kb | C++14 | 985b | 2023-10-11 19:12:54 | 2023-10-11 19:12:55 |
Judging History
answer
// Problem: F - Treelection
// Contest: Virtual Judge - 20231007 杂题选讲(UCup)- PB
// URL: https://vjudge.net/contest/586352#problem/F
// Memory Limit: 254 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<stdio.h>
template<typename dy> dy max(dy x,dy y){return x>y?x:y;}
template<typename dy> dy min(dy x,dy y){return x<y?x:y;}
const int N=1e6+5;
int n,fa[N],dp[N];
bool f[N];
bool check(int x){
for(int i=1;i<=n;i++) dp[i]=0;
for(int i=n;i>=1;i--) dp[i]=max(dp[i]-x,0),dp[fa[i]]+=dp[i]+1;
return !dp[1];
}
int main(){
int T;scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=2;i<=n;i++) scanf("%d",&fa[i]);
int l=0,r=n;
while(l<r){
// printf("%d %d ",l,r);
int mid=l+r>>1;
if(!check(mid)) l=mid+1;
else r=mid;
}
f[1]=!check(l-1);
for(int i=2;i<=n;i++) f[i]=f[fa[i]]&dp[fa[i]];
for(int i=1;i<=n;i++) {printf("%d",f[i]);f[i]=0;fa[i]=0;} puts("");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5736kb
input:
2 4 1 2 3 5 1 1 2 2
output:
1100 10000
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 104ms
memory: 5836kb
input:
10 100000 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 89 90 91 92 93 94 95 96 97 98 99 10...
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
wrong answer 1st lines differ - expected: '111111111111111111111111111111...0000000000000000000000000000000', found: '111111111111111111111111111111...1111111111111111111111111111111'