BFS adjacency Table

Source: Internet
Author: User

#include <stdio.h> #include <stdlib.h> #include <string.h>struct node{int date; struct node *next;} *h[1000],*head[1000];int v[10000],vi[10000];int i,j;int t,n,m,k;void chu (int z) {for (i=0;i<z;i++) {h[i]= (struct n        ode*) malloc (sizeof (struct node));        h[i]->next=null;    Head[i]=h[i];    }}void chu1 (int z) {for (i=0;i<z;i++) {head[i]=head[i]->next;    }}void BFS (int K) {int jin=0,chu=0;     CHU1 (n);    int W;    V[jin++]=k;    vi[k]=2;    printf ("%d", K);    while (Chu<jin) {w=v[chu++];        if (chu!=1&&vi[w]==1) {printf ("%d", W);        vi[w]=2;} while (Head[w]!=null) {if (vi[head[w]->date]==0) {V[jin++]=head[w]->date;vi[head        [w]->date]=1;        } head[w]=head[w]->next; }} printf ("\ n");}    int main () {node *p,*q;    scanf ("%d", &t);        for (i=0;i<t;i++) {scanf ("%d%d%d", &n,&m,&k);        Chu (n); Memset(Vi,0,sizeof (vi));          for (j=0;j<m;j++) {int A, B;          scanf ("%d%d", &a,&b);        p= (struct node*) malloc (sizeof (struct node));        p->next=null;        p->date=b;        h[a]->next=p;          H[a]=p;        p= (struct node*) malloc (sizeof (struct node));        p->next=null;        p->date=a;        h[b]->next=p;        H[b]=p;    } BFS (k); }}

BFS adjacency Table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.