比赛 4043级2023省选练习赛1 评测结果 AAAAAAAAAA
题目名称 树的计数 最终得分 100
用户昵称 op_组撒头屯 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2023-03-03 18:49:53
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=30+5;
int n,d[N];
ld fac[N],ans;
int main(){
	freopen ("ctree.in","r",stdin);
	freopen ("ctree.out","w",stdout);
    scanf("%d",&n);fac[0]=1;
    int sum=0,flag=0;
    for (int i=1;i<=n;i++){
        scanf("%d",&d[i]),fac[i]=fac[i-1]*i;
        if (!d[i])flag=1;
        sum+=d[i];
    }
    if (n==1&&sum==0){
        printf("1\n");return 0;
    }
    if (flag||sum!=2*n-2){
        printf("0\n");return 0;
    }
    ans=fac[n-2];
    for (int i=1;i<=n;i++)ans/=fac[d[i]-1];
    printf("%lld\n",(ll)ans);
    return 0;
}