QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277747 | #5139. DFS Order 2 | zzuqy# | WA | 2ms | 20684kb | C++11 | 2.7kb | 2023-12-06 22:17:10 | 2023-12-06 22:17:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int read()
{
int x;cin>>x;
return x;
}
int mod=998244353;
ll quick(ll a,ll b)
{
ll t=1;
while(b)
{
if(b&1)
t=t*a%mod;
b=b/2;
a=a*a%mod;
}
return t;
}
int n,f[510],siz[510],g[510][510][510],jie[510],ans[510][510],F[510],JIE[510];
int sum[510],cnt[510];
vector<int>e[510];
void dfs(int x,int fa)
{
f[x]=1;
siz[x]=1;
for(int i=0;i<e[x].size();i++)
{
if(e[x][i]==fa)
{
swap(e[x][i],e[x][e[x].size()-1]);
e[x].resize(e[x].size()-1);
}
}
for(auto y:e[x])
{
if(y==fa)
continue;
dfs(y,x);
siz[x]+=siz[y];
f[x]=1ll*f[x]*f[y]%mod;
cnt[x]++;
}
f[x]=1ll*f[x]*jie[cnt[x]]%mod;
}
queue<pair<int,int>>q;
int vis[510][510];
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
n=read();
for(int i=1;i<n;i++){
int x=read(),y=read();
e[x].push_back(y);
e[y].push_back(x);
}
jie[0]=1;
for(int i=1;i<=n+1;i++){
jie[i]=1ll*jie[i-1]*i%mod;
JIE[i]=quick(jie[i],mod-2);
}
dfs(1,0);
for(int x=n;x>=1;x--)
{
g[x][0][0]=1;
cnt[x]=0;
for(auto y:e[x])
{
sum[x]+=siz[y];
cnt[x]++;
for(int i=sum[x];i>=siz[y];i--)
for(int j=cnt[x];j>=1;j--)
g[x][j][i]=(g[x][j][i]+g[x][j-1][i-siz[y]])%mod;
}
}
q.push({1,1});
vis[1][1]=1;
ans[1][1]=1;
for(int i=1;i<=n;i++)
F[i]=quick(f[i],mod-2);
while(q.size())
{
int x=q.front().first,k=q.front().second;
q.pop();
int res=ans[x][k];
for(auto y:e[x])
{
for(int i=siz[y];i<=sum[x];i++)
for(int j=1;j<=cnt[x];j++)
g[x][j][i]=(g[x][j][i]-g[x][j-1][i-siz[y]])%mod;
sum[x]-=siz[y];
cnt[x]--;
for(int i=0;i<=sum[x];i++)
{
for(int j=0;j<=cnt[x];j++)
{
if(g[x][j][i]==0)
continue;
ans[y][k+i+1]+=1ll*res*jie[j]%mod*jie[cnt[x]-j]%mod*g[x][j][i]%mod*f[x]%mod*F[y]%mod*JIE[cnt[x]+1]%mod;
ans[y][k+i+1]%=mod;
if(vis[y][k+i+1]==0){
q.push({y,k+i+1});
vis[y][k+i+1]=1;
}
}
}
sum[x]+=siz[y];
cnt[x]++;
for(int j=cnt[x];j>=1;j--)
for(int i=1;i<=sum[x];i++)
g[x][j][i]=(g[x][j][i]+g[x][j-1][i-siz[y]])%mod;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<(ans[i][j]*f[i]%mod+mod)%mod<<' ';
cout<<'\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11688kb
input:
5 1 2 1 3 3 4 3 5
output:
4 0 0 0 0 0 2 0 0 2 0 2 2 0 0 0 0 1 2 1 0 0 1 2 1
result:
ok 25 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 15816kb
input:
10 9 2 9 6 10 5 1 5 1 6 9 3 5 8 4 3 7 9
output:
24 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 8 2 2 4 0 0 0 4 4 4 4 4 4 0 0 0 0 0 4 4 4 4 4 4 0 12 0 0 0 0 0 12 0 0 0 12 0 0 12 0 0 0 0 0 0 0 0 4 2 2 8 2 2 4 0 0 6 6 0 0 0 0 6 6 0 0 12 0 0 12 0 0 0 0 0 0 6 6 0 0 0 0 6 6
result:
ok 100 numbers
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 20684kb
input:
100 18 100 91 87 28 83 11 98 51 52 24 91 72 53 18 19 89 16 77 35 26 25 73 16 96 70 56 44 69 10 63 30 54 95 39 66 58 98 8 71 58 65 74 73 2 64 12 19 32 81 31 54 43 41 84 59 55 75 72 81 59 37 10 94 93 2 64 47 13 32 36 84 28 22 30 28 25 77 47 6 80 52 54 17 23 40 47 88 49 53 65 27 99 59 25 70 91 9 74 1 7...
output:
8388559 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 759169026 0 759169026 759169026 0 759169026 0 0 0 759169026 0 759...
result:
wrong answer 115th numbers differ - expected: '62914557', found: '759169026'