提交时间:2022-07-20 12:07:27
运行 ID: 52892
#include<iostream> #include<cstdio> #include<algorithm> #include<ctype.h> #define int long long #define eps 1e-8 using namespace std; inline int read() { int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) { if(ch=='-')f=-1; ch=getchar(); } while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar(); } return x*f; } int bin[25],sz[25]; int dp[21][21],n,a[25],aa,bb,fac; int ans; int anc(int x) { return bin[x]==x?x:bin[x]=anc(bin[x]); } double anss,sum; double cal(int x,double awa) { double ret=1.0; awa/=fac; for(int i=1; i<=x; i++) ret*=1.0-awa; return ret; } signed main() { n=read(); aa=read(),bb=read(); fac=1; for(int i=1; i<=n; i++) bin[i]=i,sz[i]=1,fac*=i; for(int i=1; i<=n; i++) { a[i]=read(); int x=anc(a[i]),y=anc(i); if(x==y) continue; bin[x]=y; sz[y]+=sz[x]; } for(int i=1; i<=n; i++) if(bin[i]==i) ans+=sz[i]-1; printf("%lld\n",ans*aa); return 0; }