QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#122636 | #4406. 独立集问题 | ezoilearner | 0 | 87ms | 59752kb | C++14 | 1.8kb | 2023-07-10 20:51:08 | 2023-07-10 20:51:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define cout cerr
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef pair<int,int> pii;
#define FR first
#define SE second
const ll inf=1e18;
inline void rd(int &x){
x=0;char ch=getchar();int f=1;
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
x*=f;
}
//是否解决 系数 类型
int n;
#define Maxn 400010
int a[Maxn];
ll F[Maxn][8];
int head[Maxn],v[Maxn],nxt[Maxn],tot=0;
void add_edge(int s,int e){
tot++;v[tot]=e;nxt[tot]=head[s];head[s]=tot;
}
int calc(int a,int b){
int a1=(a/2)&1,a2=a/4;
int b1=(b/2)&1,b2=b/4;
if(a2==1&&b2==1)return -1;
if(a2==0&&b2==0)return 0;
if(a2==0&&b2==1&&a1!=b1)return 1;
if(a2==1&&b2==0&&a1!=b1)return 2;
return 0;
}
ll fjz[8];
void dfs(int u){
rep(i,0,7)
if(i!=1&&i!=3){
int t=(i/2)&1;
if(t==0)F[u][i]=a[u];
else F[u][i]=-a[u];
}else F[u][i]=-inf;
for(int i=head[u];i;i=nxt[i]){
int t=v[i];
dfs(t);
rep(j,0,7)fjz[j]=-inf;
rep(c1,0,7)
rep(c2,0,7){
int cur=calc(c1,c2);
if(cur==-1)continue;
int ss=c2&1;
if(cur==2)ss=1;
if(ss==0)continue;
int tmp=c1;
if(cur==1)tmp|=1;
fjz[tmp]=max(fjz[tmp],F[u][c1]+F[t][c2]);
}
rep(j,0,7)F[u][j]=fjz[j];
}
}
int main(){
rd(n);
rep(i,1,n)rd(a[i]);
rep(i,2,n){
int x;rd(x);add_edge(x,i);
}
dfs(1);ll Ans=-inf;
dfs(1);
rep(i,4,7)Ans=max(Ans,F[1][i]);
printf("%lld\n",Ans);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 85ms
memory: 59752kb
input:
351493 -641495974 -401868912 -864400429 35718599 -579296290 767835327 149511992 -246228754 649472235 893048442 -292675192 -788090312 -578172296 -62289673 196890164 -120059197 -452848333 -216788131 -604555771 -240241020 376984486 -407661514 -107574590 -461679558 -470560314 -583391402 -991686079 76956...
output:
159695113349661
result:
wrong answer 1st numbers differ - expected: '175477002777567', found: '159695113349661'
Subtask #2:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 87ms
memory: 35040kb
input:
351493 915594742 688454502 456077914 208864399 625937959 102483811 538999077 529481828 400375958 387560315 83710527 83424975 330114353 684812426 68052931 28849220 295907801 535129167 967891325 124069427 644256858 757666812 558755455 178666038 177054898 795236216 848264282 669310447 328353372 3681163...
output:
132577530160578
result:
wrong answer 1st numbers differ - expected: '175766699890054', found: '132577530160578'
Subtask #3:
score: 0
Wrong Answer
Test #41:
score: 0
Wrong Answer
time: 2ms
memory: 7644kb
input:
7 247522519 398923496 -976223527 806215585 -937536479 -130552271 90576461 1 2 1 2 5 5
output:
3092505300
result:
wrong answer 1st numbers differ - expected: '3587550338', found: '3092505300'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%