20分求助
查看原帖
20分求助
320470
William_Takazaki楼主2022/10/22 16:34

rt

#include<bits/stdc++.h>
using namespace std;
int n,a[60][60];
bool f[60];
void dfs(int x){
	int i;
	if(f[x]==false){
		cout<<x<<" ";
		f[x]=true;
	}for(i=1;i<=n;i++)if(a[i][x]==1&&f[i]==false)dfs(i);
}int main(){
	int i,x,y;
	cin>>n;
	while(scanf("%d %d",&x,&y)!=EOF){
		a[x][y]=1;
		a[y][x]=1;
	}dfs(1);
	return 0;
}
2022/10/22 16:34
加载中...