传送门
解:比赛的时候思路跑偏了,看了题解才恍然大悟T T
cout的浮点数输出是真的麻烦呀
#include<bits/stdc++.h>
#define il inline
#define pb push_back
#define ms(_data,v) memset(_data,v,sizeof(_data))
#define SZ(a) int((a).size())
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
const int N=1e5+5;
//il int Add(ll &x,ll y) {return x=x+y>=mod?x+y-mod:x+y;}
//il int Mul(ll &x,ll y) {return x=x*y>=mod?x*y%mod:x*y;}
int T,n,m,k,fa[N],num[N],a[N];
vector<int> eg[N];
bool fg[N];
il void init(){
for(int i=0;i<=n;++i) fa[i]=i,num[i]=1,fg[i]=0,eg[i].clear();
}
il int find(int x){
if(x==fa[x]) return x;
else return fa[x]=find(fa[x]);
}
il void unite(int x,int y){
x=find(x),y=find(y);
if(x==y) return;
fa[x]=y,num[y]+=num[x];
}
int main(){
std::ios::sync_with_stdio(0);cin.tie(0);
cin>>T;
while(T--){
cin>>n>>m>>k;
init();
int x,y,cnt=0;
for(int i=1;i<=m;++i){
cin>>x>>y;
eg[x].pb(y),eg[y].pb(x);
}
for(int i=1;i<=k;++i){
cin>>x,fg[x]=1;
a[++cnt]=x;
}
for(int i=1;i<=n;++i){
if(fg[i]) continue;
for(auto to:eg[i]){
if(!fg[to]) unite(i,to);
}
}
int rt=find(1),res=num[rt];
if(res==n-k){
cout<<fixed<<setprecision(8)<<1.0*res<<endl;
continue;
}
double res2=0.0;
for(int i=1;i<=cnt;++i){
int tp=a[i],yes=0;
for(auto to:eg[tp]){
if(find(to)==rt){
yes=1;
break;
}
}
if(yes==1){
int sum=0;
for(auto to:eg[tp]){
if(fg[to]) continue;
if(find(to)==rt) continue;
sum+=num[find(to)];
}
res2=max(res2,1.0*sum/SZ(eg[tp]));
}
}
cout<<fixed<<setprecision(8)<<res2+1.0*res<<endl;
}
return 0;
}