QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377990#4889. 愚蠢的在线法官yyyyxhCompile Error//C++141.0kb2024-04-05 21:46:552024-04-05 21:46:56

Judging History

你现在查看的是最新测评结果

  • [2024-04-05 21:46:56]
  • 评测
  • [2024-04-05 21:46:55]
  • 提交

answer

#include <cstdio>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=x*10+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int N=500003;
typedef long long ll;
const int P=998244353;
int n,k;
int a[N],id[N];
int hd[N],ver[N<<1],nxt[N<<1],tot;
void add(int u,int v){nxt[++tot]=hd[u];hd[u]=tot;ver[tot]=v;}
int f[N],g[N];
int s[N],rk;
bool vis[N];
void dfs(int u,int fa){
	if(id[u]) f[u]=0,g[u]=1;
	else f[u]=1,g[u]=0;
	for(int i=hd[u];i;i=nxt[i]){
		int v=ver[i];
		if(v==fa) continue;
		dfs(v,u);
		g[u]=((ll)g[u]*f[v]+(ll)f[u]*g[v])%P;
		f[u]=(ll)f[u]*f[v]%P;
	}
	f[u]=(f[u]+(ll)(a[u]-a[fa])*g[u])%P;
}
int main(){
	n=read();k=read();
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=1;i<=k;++i){
		int x=read();
		if(id[x]){puts("0");return 0;}
		id[x]=i;
	}
	for(int i=1;i<n;++i){
		int u=read(),v=read();
		add(u,v);add(v,u);
	}
	dfs(1,0);
	if(f[1]<0) f[1]+=P;
	if(par&&f[1]) f[1]=P-f[1];
	printf("%d\n",f[1]);
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:46:12: error: ‘par’ was not declared in this scope
   46 |         if(par&&f[1]) f[1]=P-f[1];
      |            ^~~