首页 > 其他分享 >asas

asas

时间:2023-09-22 21:46:45浏览次数:28  
标签:10005 asas int xa xb du

#include<bits/stdc++.h>
using namespace std;

int a[1005][1005];
int n;
bool b[10005];
int c[10005][10005];
int t=0;

void dfs_xian(int x){
	cout<<x<<" ";
	for(int i=1; i<=n; i++){
		if(a[x][i]==1){
			dfs_xian(i);
		}
	}
}

void dfs_hou(int x){
	for(int i=1; i<=n; i++){
		if(a[x][i]==1){
			dfs_hou(i);
		}
	}
	cout<<x<<" "; 
}

void dfs_cen(int x){
	t=0;
	for(int i=1; i<=n; i++){
		if(a[x][i]==1){
			t++;
			c[t]=i;
			cout<<i<<endl;
		}
	}
}

int main(){
	cin>>n;
	int du[100005]={0};
	for(int i=1; i<=n-1; i++){
		cin>>xa>>xb;
		a[xa][xb]=1;
		du[xb]++;
	}
	int s;
	for(int i=1; i<=n; i++){
		if(du[i]==0){
			s=i;	
		}
	}
	dfs_xian(s);
	cout<<endl;
	dfs_hou(s);
	cout<<endl;
	dfs_cen(s);
	return 0;
}

  

标签:10005,asas,int,xa,xb,du
From: https://www.cnblogs.com/dxy09tj/p/17723441.html

相关文章