提交时间:2022-07-20 12:08:55
运行 ID: 52909
#include <bits/stdc++.h> using namespace std; int n,a,b,aa[25],f[25],siz[25],fd,ans; bitset<25> app; inline int find(int x) { return (f[x]^x)?f[x]=find(f[x]):x; } int main() { cin>>n>>a>>b; for(int i=1; i<=n; i++) cin>>aa[i],f[i]=i,siz[i]=1; for(int i=1; i<=n; i++) if(find(aa[i])^find(i)) siz[find(i)]+=siz[find(aa[i])],f[find(aa[i])]=find(i); for(int i=1; i<=n; i++) if((aa[i]^i)&&(!app[fd=find(i)])) app[fd]=1,ans+=siz[fd]-1; printf("%d.00000000000\n",ans*a); return 0; }