亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? graph.cpp

?? 讀圖并輸出圖的鄰接鏈表
?? CPP
字號:
/*****************************************
 * file: graph.cpp
 * author: 
 * data : 15:00 2006-11-15
 * copyright: free software & hardware
 * to-do: the implamtation of the graph and it's method
 *****************************************/
#include <stdio.h>
#ifdef WIN32	/* if windows we can use the assert() function */
#	include <assert.h>
#else 
#	define assert(a)
#endif
#include <list>		/* for using the std class list */
#include <vector>	/* for using the std vector class */
#include "graph.h"

/* init the graph 
 * set adj[][] = {0}
 * set size = 0
 */
int init_graph(graph *g)
{
  int i,j;
  assert(g != NULL);
  g->size = 0;
  for(i=0;i<MAX_SIZE;i++)
    for(j=0;j<MAX_SIZE;j++)
      g->adj[i][j] = 0;
  return 0;
}

/* copy the graph s to graph d
 */
int copy_graph(graph *s,graph *d)
{
  d->size = s->size;
  for(size_t i=0;i<s->size; i++){
    for(size_t j=0; j < s->size ; j++){
      d->adj[i][j] = s->adj[i][j];
    }
  }
  return 0;
}
/* read a graph from "graph.txt"
 * Each row of the file represents a link connecting the node on the first and second columns
 */
int read_graph(graph *g)
{
  FILE *fd;
  unsigned int src,dst;
	
  assert(g != NULL);
  fd = fopen("graph.txt","r");
  if( -1 == (int)fd ){
    return -1;	/* error while open the file */
  }
  while( fscanf(fd,"%d %d",&src,&dst) != EOF ){	/* read from the file line by line */
    if(src >= MAX_SIZE || dst >= MAX_SIZE){
      return -1;	/* the number of the bertex must small then 50 */
    }
    if(src >= g->size) g->size = src + 1;	/* get the size */
    if(dst >= g->size) g->size = dst + 1;
    g->adj[src][dst] = 1;	/* so there is a connection between src and dst */
    g->adj[dst][src] = 1;	/* because it is a undirected graph */
  }
  fclose(fd);
  return 0;	/* success return 0 */
}
/* reads the graph structure and prints the graph in the following format: 
 *		v-- a list of its adjacent vertices 
 */
int print_graph(graph *g)
{
  size_t i,j;
	
  assert(g != NULL);
  for(j=0;j<g->size;j++){
    printf("%d -- ",j);
    for(i=0;i<g->size;i++){
      if(g->adj[j][i])	/* if v--i then g->adj[v][i] will equ to 1 */
	printf("%d,",i);
    }
    printf("\n");
  }
  return 0;
}
/* takes a graph G, a source node s, and a destination d as parameters, 
 * and returns the length of the shortest path from s to d. 
 * Bonus:Print the node sequence of the shortest path.
 */
typedef struct _node
{
  int index;			/* vertex index in the graph */
  int father;			/* father's index in the array */
} node;
int shortest_path(graph *g,unsigned int s,unsigned int d) /* use BFS */
{
  std::vector<node> bfs_array;
  unsigned int now_point = 0;		/* the element's index in the bfs_array */
  int is_visited[MAX_SIZE] = {0};	/* the flag array to notify if the vertex has visited */

  assert(g != NULL);
  if(s < 0 || s >= g->size || d < 0 || d >= g->size){ /* use the wrong argument */
    return -1;
  }
  while(1){
    node n;			/* the temp node,use for operation */
    if(bfs_array.size() == 0){	/* have no element we put the first one in it */
      n.index = s;		/* the first element is source vertex "s" */
      n.father = -1;		/* have no father */
      bfs_array.push_back(n);	/* put into array */
      is_visited[s] = 1;	/* now vertex "s" is visited */
      continue;
    }
    for(unsigned int j = 0; j < g->size; j ++){ /* put each one connected to vertex into the array  */
      int vertex = bfs_array[now_point].index;
      if(g->adj[vertex][j] == 1 && is_visited[j] == 0){ /* there is a connection between vertex and j and j has'nt been visited */
	n.index = j;
	n.father = now_point;	/* j's father is vertex, and vertex's index number is now_point */
	bfs_array.push_back(n);
	is_visited[j] = 1;	/* j has been visited */
	if(j == d){
	  now_point = bfs_array.size() - 1 ;
	  goto FINDED;	/* arrive at d!!! */
	}
      }
    }
    now_point ++;
    if(now_point >= bfs_array.size()){ /* there is no element remain */
      break;
    }
  }
  return -1;			/* s not connected with d return -1 */

 FINDED:			/* if s can arrive at d then do the following things */
  int len = 0;
  while(bfs_array[now_point].father != -1 && bfs_array[now_point].index != s){ // print the path one by one
    printf("%d----",bfs_array[now_point].index);
    now_point = bfs_array[now_point].father;
    len ++;	
  }
  printf("%d\n",bfs_array[now_point].index);
  return len;	/* return the length of the path */
}
/* to test the graph g if it is connected 
 * in an other word, if it is a forest
 *  use the algorthm warshall, see the book "introduction to the design & analysis of algorithms"
 */
int is_connected(graph *g)
{
  unsigned int i,j,k;
  graph tmp;

  assert(g != NULL);
  copy_graph (g, &tmp);
  for(k = 0; k < tmp.size ; k++)
    for(i = 0 ; i < tmp.size ; i++)
      for(j = 0 ; j < tmp.size ; j++){
	if(tmp.adj[i][j] == 1) continue;
	if(tmp.adj [i][k] == 1 && tmp.adj [k][j] == 1){
	  tmp.adj [i][j] = 1;
	}
      }
  for(i = 0; i< tmp.size; i++)	/* if the elements in tmp matrix are all 1s then it is connected */
    for(j = 0; j < tmp.size; j++){
      if(tmp.adj [i][j] == 0) return 0;
    }
  return 1;
}
/* to test the graph if it is a tree
 */
int is_tree(graph *g)
{
  assert (g != NULL);
  if(is_connected(g) && !has_cycle(g,0)) /* if the graph is connect and has no cycle then it is a tree */
    return 1;
  return 0;
}
/* to test the graph if it has a cycle,
 * if it has print it
 */
int has_cycle(graph *g,int print)
{
  std::vector<node> bfs_array;
  unsigned int i,now_point = 0;		/* the element's index in the bfs_array */
  int is_visited[MAX_SIZE] = {0};	/* the flag array the notify if the vertex has visited */
  int result = 0;

  while(1){
    node n;			/* the temp node,use for operation */
    if(bfs_array.size() == 0){	/* have no element we put the first one in it */
      for(i=0; i<g->size; i++)
	if(is_visited[i] == 0){
	  n.index = i;		/* the first element is source vertex "s" */
	  n.father = -1;		/* have no father */
	  is_visited[i] = 1;	/* now vertex "s" is visited */
	  bfs_array.push_back(n);	/* put into array */
	  break;
	}
      if(bfs_array.size() == 0) return result;
      continue;
    }
    for(unsigned int j = 0; j < g->size; j ++){ /* put each one connected to vertex into the array  */
      int vertex = bfs_array[now_point].index;
      if(g->adj[vertex][j] == 1 && is_visited[j] == 0){ /* there is a connection between vertex and j and j has'nt been visited */
	n.index = j;
	n.father = now_point;	/* j's father is vertex, and vertex's index number is now_point */
	bfs_array.push_back(n);
	is_visited[j] = 1;	/* j has been visited */
      } else if(g->adj[vertex][j] == 1 && is_visited[j] == 1){
	if(j != bfs_array[now_point].father){ /* there is a cycle */
	  result = 1;
	  if(print == 1){	/* print the cycle */
	    printf("%d",j);
	    int tmp_point = now_point;
	    while(g->adj [ bfs_array[tmp_point].index ][j]  != 1 || tmp_point == now_point){
	      printf ("----%d",bfs_array[tmp_point].index);
	      tmp_point = bfs_array[tmp_point].father;
	    }
	    printf ("----%d",bfs_array[tmp_point].index);
	    printf("----%d\n",j);
	  }
	}
      }
    }
    now_point ++;
    if(now_point >= bfs_array.size()){ /* there is no element remain */
      bfs_array.resize(0);
    }
  }
  return result;			/* s not connected with d return -1 */
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕字幕中文在线中不卡视频| 日韩国产欧美三级| 一级中文字幕一区二区| 国内国产精品久久| 欧美三级蜜桃2在线观看| 国产亚洲欧美色| 免费观看日韩av| 日本精品一级二级| 中文幕一区二区三区久久蜜桃| 五月天亚洲婷婷| 一本大道久久精品懂色aⅴ| 久久综合久久鬼色| 日本欧美一区二区在线观看| 日本久久一区二区| 国产精品初高中害羞小美女文| 美女脱光内衣内裤视频久久影院| 欧美在线免费视屏| 亚洲综合丁香婷婷六月香| 成人成人成人在线视频| www一区二区| 国产美女在线精品| 欧美va在线播放| 青草av.久久免费一区| 欧美日韩激情在线| 午夜欧美2019年伦理| 欧洲精品在线观看| 亚洲综合一区在线| 欧美视频日韩视频在线观看| 亚洲精品写真福利| 91亚洲国产成人精品一区二三 | 欧美精品乱码久久久久久| 日韩一区在线看| av资源网一区| 最新国产成人在线观看| 色综合一区二区| 亚洲精品国产品国语在线app| www.欧美色图| 亚洲乱码中文字幕| 在线一区二区视频| 亚洲一区二区三区在线看| 欧美视频一区二区在线观看| 午夜视频在线观看一区二区| 6080午夜不卡| 国产一区二区视频在线播放| ww亚洲ww在线观看国产| 国产成人精品亚洲午夜麻豆| 国产欧美综合在线观看第十页| 国产成人av一区| 亚洲欧美国产毛片在线| 欧美日韩国产一级片| 青青草精品视频| 久久精品视频在线免费观看| 97精品超碰一区二区三区| 亚洲男女毛片无遮挡| 欧美日韩精品免费观看视频| 麻豆freexxxx性91精品| 中文字幕av在线一区二区三区| 99精品久久只有精品| 婷婷中文字幕综合| 久久久九九九九| 91国产视频在线观看| 久久精品国产亚洲一区二区三区| 国产亚洲综合在线| 色猫猫国产区一区二在线视频| 日本三级韩国三级欧美三级| 国产欧美综合在线观看第十页| 在线观看视频一区二区欧美日韩| 免费在线视频一区| 中文字幕在线免费不卡| 日韩欧美在线网站| 91影视在线播放| 久久国产尿小便嘘嘘尿| 最好看的中文字幕久久| 欧美一区二区三区男人的天堂| 国产成人精品亚洲777人妖| 亚洲第一激情av| 国产精品国产三级国产| 日韩一级片在线播放| 91麻豆福利精品推荐| 久久99精品久久久久久国产越南 | 国产日产精品1区| 欧美日韩一区 二区 三区 久久精品| 另类欧美日韩国产在线| 亚洲一区免费观看| 中文字幕精品一区二区精品绿巨人 | 国产精品久久精品日日| 91精品在线一区二区| 91丨porny丨最新| 国产精品一区免费在线观看| 丝袜美腿亚洲综合| 亚洲自拍偷拍麻豆| 国产精品久久久久影视| 久久一留热品黄| 91精品国产色综合久久不卡蜜臀 | 日韩成人精品在线| 亚洲人成精品久久久久久| 久久精品在线免费观看| 日韩亚洲欧美在线| 在线观看91精品国产麻豆| 91免费观看国产| 成人av动漫在线| 国产精品456| 国产一区二区三区香蕉| 日韩成人一区二区| 五月天一区二区三区| 一区二区高清免费观看影视大全 | 精品国产三级电影在线观看| 欧美性受极品xxxx喷水| 91九色02白丝porn| 色狠狠一区二区| 色综合久久99| 91国偷自产一区二区三区成为亚洲经典| 成人av动漫网站| 91视视频在线观看入口直接观看www | 国产精品嫩草影院av蜜臀| 国产三级精品三级在线专区| 26uuu精品一区二区在线观看| 2欧美一区二区三区在线观看视频| 日韩一区二区三区四区五区六区| 日韩视频在线你懂得| 日韩美女视频一区二区在线观看| 在线不卡的av| 精品国产电影一区二区| 久久久欧美精品sm网站| 国产精品亲子伦对白| 国产精品久久久久久久久久久免费看 | www.日韩在线| 色综合久久久久久久久| 欧美性生活大片视频| 欧美日本一区二区在线观看| 欧美一区二区三区啪啪| 久久久国产精华| 国产精品美女久久久久久久网站| 亚洲日本在线a| 婷婷成人激情在线网| 午夜国产精品一区| 美女爽到高潮91| 国产成人午夜视频| 色久优优欧美色久优优| 欧美日韩国产bt| 国产日韩一级二级三级| 一区二区三区产品免费精品久久75| 亚洲成av人片在线观看| 久久国产精品第一页| 成人免费视频国产在线观看| 色婷婷亚洲精品| 日韩欧美激情四射| 国产精品每日更新| 天堂久久久久va久久久久| 国产精品一区二区你懂的| 欧美性受极品xxxx喷水| 精品成a人在线观看| 一区二区在线观看免费| 精品夜夜嗨av一区二区三区| 91在线porny国产在线看| 欧美一区二区在线视频| 中文字幕亚洲电影| 蜜桃精品在线观看| 色狠狠一区二区| 国产女人18水真多18精品一级做| 一二三区精品视频| 国产成人精品1024| 777xxx欧美| 最新久久zyz资源站| 麻豆91在线观看| 欧美色综合天天久久综合精品| 久久免费看少妇高潮| 亚洲成av人片在www色猫咪| 成人国产精品视频| 精品国产123| 天天色 色综合| 91在线视频18| 国产欧美日韩卡一| 日本美女视频一区二区| 在线观看三级视频欧美| 国产清纯美女被跳蛋高潮一区二区久久w| 亚洲影视在线播放| 97se亚洲国产综合自在线不卡| 精品va天堂亚洲国产| 日本亚洲天堂网| 欧美撒尿777hd撒尿| 自拍偷拍欧美激情| 国产99精品视频| 精品电影一区二区| 久久 天天综合| 日韩精品一区二区三区三区免费| 丝袜美腿亚洲一区二区图片| 色狠狠综合天天综合综合| 自拍偷在线精品自拍偷无码专区| 福利一区二区在线| 国产亚洲欧美日韩日本| 韩国女主播成人在线观看| 欧美不卡在线视频| 精品无人区卡一卡二卡三乱码免费卡| 日韩亚洲欧美高清| 精品一区中文字幕| 久久综合av免费| 国产精选一区二区三区| 日本一区二区视频在线| 风间由美中文字幕在线看视频国产欧美|