标签:des style http io ar color os sp for
1 6 7 0 0 3 0 4 1 4 1 5 2 3 2 4 3 5
0 3 4 2 5 1
#include <iostream> #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<malloc.h> #include<stack> using namespace std; int map[110][110]; int vis[110]; int que[110]; int p[110]; int s,e; int n,m,k,t,len; int bfs() { s=0;e=0; que[e++]=t; while(s<e) { int a=que[s++]; for(int i=0; i<k; i++) { if(map[a][i]==1) { que[e++]=i; map[a][i]=map[i][a]=0; } if(vis[a]==0) { p[len++]=a; vis[a]=1; } } } } int main() { cin>>n; int u,v; while(n--) { cin>>k>>m>>t; len=0; memset(map,0,sizeof(map)); memset(vis,0,sizeof(vis)); for(int i=0; i<m; i++) { cin>>u>>v; map[u][v]=map[v][u]=1; } bfs(); for(int i=0; i<len-1; i++) cout<<p[i]<<" "; cout<<p[len-1]<<endl; } }
标签:des style http io ar color os sp for
原文地址:http://blog.csdn.net/lucky_vikey/article/details/41597243