QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#783242#9566. TopologyDarwin_ArnoldCompile Error//C++142.2kb2024-11-26 02:54:232024-11-26 02:54:25

Judging History

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

  • [2024-11-26 02:54:25]
  • 评测
  • [2024-11-26 02:54:23]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5010;
int mod=998244353;
int n;
vector<int>G[N];
int L[N];
int sz[N];
int p[N];
int f[N];
int g[N][N];
int dp[N][N];
int S[N][N];
int ans[N];
int fast_pow(int a,int m)
{
    int base=a;
    int res=1;
    while(m)
    {
        if(m&1)res=(int)((res*1ll*base)%mod);
        base=(int)((base*1ll*base)%mod);
        m>>=1;
    }
    return res;
}
int mod_inverse(int x)
{
    return (int)(fast_pow(x,mod-2));
}
int C(int x,int y)
{
    return (int)((((L[x]*1ll*mod_inverse(L[y]))%mod)*1ll*mod_inverse(L[x-y]))%mod);
}
void dfs_1(int u,int fa)
{
    int temp=L[sz[u]-1];
    for(int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        dfs_1(v,u);
        temp=(int)((temp*1ll*f[v])%mod);
        temp=(int)((temp*1ll*mod_inverse(L[sz[v]]))%mod);
        //printf("%d\n",temp);
    }
    f[u]=temp;
    for(int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        g[u][v]=(int)((((f[u]*1ll*mod_inverse(f[v]))%mod)*mod_inverse(C(sz[u]-1,sz[v])))%mod);
    }
}
void dfs_2(int u,int fa)
{
    if(u!=1)
    {
        for(int i=1;i<=n;i++)
        {
            S[fa][i]=(int)(((S[fa][i-1]*1ll+(dp[fa][i]*1ll*C(n-sz[u]-i,sz[fa]-sz[u]-1))%mod))%mod);
            dp[u][i]=(int)(g[fa][u]*1ll*S[fa][i-1])%mod;
        }
    }
    for(int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        dfs_2(v,u);
    }
}
int main()
{
    scanf("%lld",&n);
    L[0]=1;
    for(int i=1;i<=n;i++)L[i]=(int)((i*1ll*L[i-1])%mod);
    for(int i=2;i<=n;i++)
    {
        int x;
        scanf("%lld",&x);
        p[i]=x;
        G[x].push_back(i);
    }
    for(int i=1;i<=n;i++)sz[i]=1;
    for(int i=n;i>=2;i--)sz[p[i]]+=sz[i];
    dp[1][1]=1;
    dfs_1(1,0);
    dfs_2(1,0);
    for(int i=1;i<=n;i++)
    {
        ans[i]=(int)((((dp[i][i]*1ll*f[i])%mod)*1ll*C(n-i,sz[i]-1))%mod);
    }
    /*
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            printf("%d ",g[i][j]);
        }
        printf("\n");
    }
    */
    for(int i=1;i<=n;i++)
    {
        printf("%lld ",ans[i]);
    }
    return 0;
}

Details

cc1plus: error: ‘::main’ must return ‘int’
answer.code: In function ‘int main()’:
answer.code:72:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   72 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
answer.code:78:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   78 |         scanf("%lld",&x);
      |         ~~~~~^~~~~~~~~~~