Submission #1437809


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
vector<int> G[222];
int n;
int dp[222][222];
int dp2[222][222];
int r[222];
int dp3[222][222][222];


int dfs2(int i,int j,int k){
  if(~dp3[i][j][k]) return dp3[i][j][k];
  if(i+j+k==0) return 1;
  int res=0;
  if(i>0&&j>0&&k>0) (res+=dfs2(i-1,j-1,k-1))%=MOD;
  if(i>0&&k>0) (res+=dfs2(i-1,j,k-1))%=MOD;
  if(j>0&&k>0) (res+=dfs2(i,j-1,k-1))%=MOD;
  return dp3[i][j][k]=res;
}

void calc(int v){
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(int i=0;i<(int)G[v].size();i++){
    for(int j=0;j<=n;j++){
      for(int k=0;k<=n;k++){
	if(j+k>n) continue;
	for(int l=max(j,k);l<=j+k;l++){
	  (dp[i+1][l]+=(dp[i][j]*dp2[G[v][i]][k])%MOD*dfs2(j,k,l))%=MOD;
	}
      }
    }
  }
  /*//
  for(int i=0;i<=(int)G[v].size();i++)
    for(int j=0;j<=n;j++)
      cout<<v<<" "<<i<<" "<<j<<":"<<dp[i][j]<<endl;
  //*/
}

void dfs(int v){
  for(int u:G[v]) dfs(u);
  memset(dp2[v],0,sizeof(dp2[v]));
  calc(v);
  for(int i=0;i<=n;i++)
    dp2[v][i+1]=dp[G[v].size()][i];
}
signed main(){
  cin>>n;
  memset(r,0,sizeof(r));
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    G[a].push_back(b);
    r[b]=1;
  }
  memset(dp3,-1,sizeof(dp3));
  int idx;
  for(int i=0;i<n;i++)
    if(!r[i]) dfs(i),idx=i;
  int ans=0;
  for(int i=0;i<=n;i++)
    (ans+=dp2[idx][i])%=MOD;
  cout<<ans<<endl;
  return 0;
}

Submission Info

Submission Time
Task E - 順位付け
User beet
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1451 Byte
Status AC
Exec Time 944 ms
Memory 86528 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 55
Set Name Test Cases
All 00-sample1.txt, 00-sample2.txt, 00-sample3.txt, 00-sample4.txt, 00-sample5.txt, random00.txt, random01.txt, random02.txt, random03.txt, random04.txt, random05.txt, random06.txt, random07.txt, random08.txt, random09.txt, random10.txt, random11.txt, random12.txt, random13.txt, random14.txt, random15.txt, random16.txt, random17.txt, random18.txt, random19.txt, random20.txt, random21.txt, random22.txt, random23.txt, random24.txt, random25.txt, random26.txt, random27.txt, random28.txt, random29.txt, random30.txt, random31.txt, random32.txt, random33.txt, random34.txt, random35.txt, random36.txt, random37.txt, random38.txt, random39.txt, random40.txt, random41.txt, random42.txt, random43.txt, random44.txt, random45.txt, random46.txt, random47.txt, random48.txt, random49.txt
Case Name Status Exec Time Memory
00-sample1.txt AC 22 ms 86528 KB
00-sample2.txt AC 22 ms 86528 KB
00-sample3.txt AC 22 ms 86528 KB
00-sample4.txt AC 23 ms 86528 KB
00-sample5.txt AC 22 ms 86528 KB
random00.txt AC 22 ms 86528 KB
random01.txt AC 22 ms 86528 KB
random02.txt AC 22 ms 86528 KB
random03.txt AC 22 ms 86528 KB
random04.txt AC 22 ms 86528 KB
random05.txt AC 22 ms 86528 KB
random06.txt AC 22 ms 86528 KB
random07.txt AC 22 ms 86528 KB
random08.txt AC 22 ms 86528 KB
random09.txt AC 22 ms 86528 KB
random10.txt AC 23 ms 86528 KB
random11.txt AC 22 ms 86528 KB
random12.txt AC 22 ms 86528 KB
random13.txt AC 22 ms 86528 KB
random14.txt AC 23 ms 86528 KB
random15.txt AC 23 ms 86528 KB
random16.txt AC 23 ms 86528 KB
random17.txt AC 22 ms 86528 KB
random18.txt AC 23 ms 86528 KB
random19.txt AC 22 ms 86528 KB
random20.txt AC 848 ms 86528 KB
random21.txt AC 849 ms 86528 KB
random22.txt AC 850 ms 86528 KB
random23.txt AC 848 ms 86528 KB
random24.txt AC 847 ms 86528 KB
random25.txt AC 848 ms 86528 KB
random26.txt AC 847 ms 86528 KB
random27.txt AC 848 ms 86528 KB
random28.txt AC 854 ms 86528 KB
random29.txt AC 848 ms 86528 KB
random30.txt AC 847 ms 86528 KB
random31.txt AC 847 ms 86528 KB
random32.txt AC 846 ms 86528 KB
random33.txt AC 848 ms 86528 KB
random34.txt AC 856 ms 86528 KB
random35.txt AC 847 ms 86528 KB
random36.txt AC 848 ms 86528 KB
random37.txt AC 848 ms 86528 KB
random38.txt AC 852 ms 86528 KB
random39.txt AC 849 ms 86528 KB
random40.txt AC 859 ms 86528 KB
random41.txt AC 907 ms 86528 KB
random42.txt AC 944 ms 86528 KB
random43.txt AC 849 ms 86528 KB
random44.txt AC 847 ms 86528 KB
random45.txt AC 851 ms 86528 KB
random46.txt AC 853 ms 86528 KB
random47.txt AC 850 ms 86528 KB
random48.txt AC 854 ms 86528 KB
random49.txt AC 857 ms 86528 KB