社区讨论

黄题求助

学术版参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@m16h502c
此快照首次捕获于
2024/09/17 21:32
去年
此快照最后确认于
2025/11/04 21:00
4 个月前
查看原帖
代码:
CPP
#include<bits/stdc++.h>
#define ll long long
#define f(a,b,c) for(ll a=b;a<=c;++a)
using namespace std;
inline int read(){int f=1,x=0;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^48);ch=getchar();}return f*x;}
ll n,m,q,x,y,ans,tot;
ll a[5005][5005],bo[10000005];
void dfs(ll dep,ll sum,ll k)
{
	sum++;
	if(y==0)
	{
		ans=max(ans,sum);
		return;
	}
	ll p=0;
	f(i,1,n)
	{
		if(a[dep][i]&&!bo[i])
		{
			bo[i]=1;
			dfs(i,sum,k-1);
			bo[i]=0; 
			p=1;
		}
	}
	if(!p)
	{
		ans=max(ans,sum);
		return;
	}
	return;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	n=read();
	m=read();
	q=read();
	f(i,1,m)
	{
		x=read();
		y=read();
		a[x][y]=1;
		a[y][x]=1;
	} 
	f(i,1,q)
	{
		x=read();
		y=read();
		ans=0;
		bo[x]=1;
		dfs(x,0,y);
		bo[x]=0;
		tot+=ans;
//		cout<<ans<<' ';
	}
	printf("%.2f",tot*1.00/n);
	return 0; 
}
有没有大佬帮帮蒟蒻啊

回复

2 条回复,欢迎继续交流。

正在加载回复...