标签:des style blog io color sp for 数据 div
1 4 4 0 1 0 2 0 3 2 3
0 1 2 3
#include<stdio.h> #include<string.h> #define MAXN 110 int mapp[MAXN][MAXN]; int vis[MAXN], cnt=0; void DFS(int t, int n) { int u = t, j; for(j=0; j<n; j++) { if(mapp[u][j]==1 && !vis[j]) { vis[j] =1; cnt++; if(cnt==n-1) printf("%d\n", j); else printf("%d ", j); DFS(j, n); } } } int main() { int n, m, t; scanf("%d", &t); while(t--) { int i, x, y; memset(mapp, 0, sizeof(mapp)); memset(vis, 0, sizeof(vis)); scanf("%d%d", &n, &m); for(i=0; i<m; i++) { scanf("%d%d", &x, &y); mapp[x][y] = 1;//无向图 mapp[y][x] = 1; } vis[0] = 1; printf("0 "); cnt = 0; DFS(0, n); } return 0; }
标签:des style blog io color sp for 数据 div
原文地址:http://www.cnblogs.com/6bing/p/4119057.html