提交时间:2022-07-20 11:54:44

运行 ID: 52782

#include<bits/stdc++.h> #define I using #define love namespace #define Elaina std I love Elaina; const int N=30; int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); } return x*f; } int n,a,b,p[N],fi[N],times; long long fac=1; int find(int x){ return x==fi[x]?x:fi[x]=find(fi[x]); } int main(){ n=times=read(),a=read(),b=read(); for(int i=2;i<=n;i++)fac=1ll*fac*i; for(int i=1;i<=n;i++)fi[i]=i; for(int i=1;i<=n;i++){ p[i]=read(); if(find(i)!=find(p[i]))fi[find(i)]=find(p[i]); } for(int i=1;i<=n;i++)if(i==fi[i])times--; if(b>=times*a){ printf("%.8lf",(double)a*times); return 0; } printf("%.8lf",(double)fac*b); return 0; }