随笔分类 - 图
摘要:题目描述请定一个无向图,顶点编号从0到n-1,用深度优先搜索(DFS),遍历并输出。遍历时,先遍历节点编号小的。输入输入第一行为整数n(0 2 #include 3 int p[101][101];//标记边 4 int o[101];//标记点 5 int num[101];//存遍历完的点 6 int z; 7 //dfs算法 8 void dfs(int k,int v) 9 {10 int j;11 o[v] = 1;12 num[z++] = v;13 for(j = 0;j <= k-1;j ++)14 {15 if(p[...
阅读全文
摘要:Catch That CowTime Limit:2000MSMemory Limit:65536KTotal Submissions:37622Accepted:11666DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a pointN(0 ≤N≤ 100,000) on a number line and the cow is at a pointK(0 ≤K≤ 100,000) on the
阅读全文
摘要:题目描述给定一个无向连通图,顶点编号从0到n-1,用广度优先搜索(BFS)遍历,输出从某个顶点出发的遍历序列。(同一个结点的同层邻接点,节点编号小的优先遍历)输入输入第一行为整数n(0 2 #include 3 int map[110][110]; 4 int vis[110],que[110]; 5 int m,k,t,flag; 6 void bfs(int t) 7 { 8 int l=0,r=0,tt,j; 9 que[r++]=t;10 while(l<r)11 {12 tt=que[l++];13 if(flag==1...
阅读全文