提交时间:2022-07-20 12:02:06
运行 ID: 52828
#include<cstdio> #define rep(a,b,c) for(int c(a);c<=(b);++c) inline int read() { int res=0;char ch=getchar();while(ch<'0'||ch>'9')ch=getchar(); while(ch<='9'&&ch>='0')res=res*10+(ch^48),ch=getchar();return res; } const int N=25;int a[N],ans;bool vis[N]; int main() { int n=read(),A=read(),B=read(); rep(1,n,i)a[i]=read(); rep(1,n,i)if(!vis[i]) { int x=i,c=0;vis[x]=true; do vis[x]=true,++c,x=a[x];while(!vis[x]); ans+=c-1; } printf("%.20Lf",(long double)A*ans); }