QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#122626 | #4406. 独立集问题 | ezoilearner | Compile Error | / | / | C++14 | 3.7kb | 2023-07-10 20:44:01 | 2023-07-10 20:44:04 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-07-10 20:44:04]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-07-10 20:44:01]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
#define cout cerr
#define rep(i,a,b) for(int i=(a);i<=(b);++i)#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;
if(cur==1)c1|=1;
fjz[c1]=max(fjz[c1],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;
}
#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;
if(cur==1)c1|=1;
fjz[c1]=max(fjz[c1],F[u][c1]+F[t][c2]);
}
rep(j,0,7)F[u][j]=fjz[j];
}
}
int main(){
freopen("ex_1.in","r",stdin);
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;
}
Details
answer.code:5:18: error: '#' is not followed by a macro parameter 5 | #define rep(i,a,b) for(int i=(a);i<=(b);++i)#include<bits/stdc++.h> | ^ answer.code:95:10: error: redefinition of ‘const ll inf’ 95 | const ll inf=1e18; | ^~~ answer.code:16:10: note: ‘const ll inf’ previously defined here 16 | const ll inf=1e18; | ^~~ answer.code:97:13: error: redefinition of ‘void rd(int&)’ 97 | inline void rd(int &x){ | ^~ answer.code:18:13: note: ‘void rd(int&)’ previously defined here 18 | inline void rd(int &x){ | ^~ answer.code:111:5: error: redefinition of ‘int n’ 111 | int n; | ^ answer.code:32:5: note: ‘int n’ previously declared here 32 | int n; | ^ answer.code:113:5: error: redefinition of ‘int a [400010]’ 113 | int a[Maxn]; | ^ answer.code:34:5: note: ‘int a [400010]’ previously declared here 34 | int a[Maxn]; | ^ answer.code:114:4: error: redefinition of ‘ll F [400010][8]’ 114 | ll F[Maxn][8]; | ^ answer.code:35:4: note: ‘ll F [400010][8]’ previously declared here 35 | ll F[Maxn][8]; | ^ answer.code:115:5: error: redefinition of ‘int head [400010]’ 115 | int head[Maxn],v[Maxn],nxt[Maxn],tot=0; | ^~~~ answer.code:36:5: note: ‘int head [400010]’ previously declared here 36 | int head[Maxn],v[Maxn],nxt[Maxn],tot=0; | ^~~~ answer.code:115:16: error: redefinition of ‘int v [400010]’ 115 | int head[Maxn],v[Maxn],nxt[Maxn],tot=0; | ^ answer.code:36:16: note: ‘int v [400010]’ previously declared here 36 | int head[Maxn],v[Maxn],nxt[Maxn],tot=0; | ^ answer.code:115:24: error: redefinition of ‘int nxt [400010]’ 115 | int head[Maxn],v[Maxn],nxt[Maxn],tot=0; | ^~~ answer.code:36:24: note: ‘int nxt [400010]’ previously declared here 36 | int head[Maxn],v[Maxn],nxt[Maxn],tot=0; | ^~~ answer.code:115:34: error: redefinition of ‘int tot’ 115 | int head[Maxn],v[Maxn],nxt[Maxn],tot=0; | ^~~ answer.code:36:34: note: ‘int tot’ previously defined here 36 | int head[Maxn],v[Maxn],nxt[Maxn],tot=0; | ^~~ answer.code:116:6: error: redefinition of ‘void add_edge(int, int)’ 116 | void add_edge(int s,int e){ | ^~~~~~~~ answer.code:37:6: note: ‘void add_edge(int, int)’ previously defined here 37 | void add_edge(int s,int e){ | ^~~~~~~~ answer.code:120:5: error: redefinition of ‘int calc(int, int)’ 120 | int calc(int a,int b){ | ^~~~ answer.code:41:5: note: ‘int calc(int, int)’ previously defined here 41 | int calc(int a,int b){ | ^~~~ answer.code:130:4: error: redefinition of ‘ll fjz [8]’ 130 | ll fjz[8]; | ^~~ answer.code:51:4: note: ‘ll fjz [8]’ previously declared here 51 | ll fjz[8]; | ^~~ answer.code:131:6: error: redefinition of ‘void dfs(int)’ 131 | void dfs(int u){ | ^~~ answer.code:52:6: note: ‘void dfs(int)’ previously defined here 52 | void dfs(int u){ | ^~~ answer.code:156:5: error: redefinition of ‘int main()’ 156 | int main(){ | ^~~~ answer.code:77:5: note: ‘int main()’ previously defined here 77 | int main(){ | ^~~~ answer.code: In function ‘int main()’: answer.code:157:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 157 | freopen("ex_1.in","r",stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~