为什么k=0这样写WA了
查看原帖
为什么k=0这样写WA了
235901
Always_Remember_It楼主2023/9/13 17:26
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2510;
const int M=20010;
int now[N][M],cnt[M];
int n,a[M],f[M],maxn=-111;
bool vis[M];
void dfs(int num,int step){
	if(step==5){
		int ans=0;
		for(int i=1;i<=4;i++){
			//cout<<f[i]<<" ";
			ans+=a[f[i]];
		}
		//cout<<endl;
		maxn=max(maxn,ans);
		return;
	}
	for(int i=1;i<=cnt[num];i++){
		if(vis[now[num][i]]) continue;
		if(now[num][i]==1) continue;
		vis[now[num][i]]=1;
		f[step]=now[num][i];
		dfs(f[step],step+1);
		f[step]=0;
		vis[now[num][i]]=0;
	}
}
signed main(){
	int m,k;cin>>n>>m>>k;
	for(int i=2;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=m;i++){
		int x,y;cin>>x>>y;
		/*if(x==1){
			now[1][++cnt[1]]=y;
			continue;
		}
		if(y==1){
			now[1][++cnt[1]]=x;
			continue;
		}*/
		now[x][++cnt[x]]=y;
		now[y][++cnt[y]]=x;
	}
	/*cout<<cnt[1]<<endl;
	for(int i=1;i<=cnt[1];i++){
		cout<<now[1][i]<<" ";
	}
	cout<<endl;    */
	dfs(1,1);
	cout<<maxn<<endl;
	return 0;
}
2023/9/13 17:26
加载中...