当前位置: 首页>>代码示例>>C++>>正文


C++ DFS函数代码示例

本文整理汇总了C++中DFS函数的典型用法代码示例。如果您正苦于以下问题:C++ DFS函数的具体用法?C++ DFS怎么用?C++ DFS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DFS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ne

bool TopologicalGraph::CheckBiconnected()
  {if(debug())DebugPrintf("   CheckBionnected");
  if(Set().exist(PROP_BICONNECTED))return true;
  if(nv() < 3 || ne() < 3)return false;
  if(debug())DebugPrintf("Executing CheckBionnected");
  int m = ne();
  int n = nv();
  if (m==0) return true;
  svector<tvertex> nvin(-m,m);   nvin.SetName("TG:Bicon:nvin");
  svector<tvertex> low(0,n);     low.SetName("TG:Bicon:low"); 

  if(!DFS(nvin)) // not connected ...
      return false;
  _Bicon Bicon(n);
  int ret = bicon(n,m,nvin,Bicon,low);
  if(ret)
      {Prop1<int> isbicon(Set(),PROP_BICONNECTED);
      Prop1<int> is_con(Set(),PROP_CONNECTED);
      return true;
      }
  return false;
  }
开发者ID:beauby,项目名称:pigale,代码行数:22,代码来源:TopoAlgs.cpp

示例2: ListComponents

void ListComponents()
{
    int i;
    for (i = 0; i < G->n; i++) {
        if (!G->Visited[i]) {
            printf("{ ");
            DFS(i);
            printf("}\n");
        }
    }

    for (i = 0; i < G->n; i++)
        G->Visited[i] = 0;

    for (i = 0; i < G->n; i++) {
        if (!G->Visited[i]) {
            printf("{ ");
            BFS(i);
            printf("}\n");
        }
    }
}
开发者ID:yanxutao,项目名称:DataStructure,代码行数:22,代码来源:061.c

示例3: DFS

int DFS(int x)
{
    visx[x] = 1;
    for (int y = 1;y <= ny;y ++)
    {
        if (visy[y])
            continue;
        int t = lx[x] + ly[y] - w[x][y];
        if (t == 0)       //
        {
            visy[y] = 1;
            if (link[y] == -1||DFS(link[y]))
            {
                link[y] = x;
                return 1;
            }
        }
        else if (slack[y] > t)  //不在相等子图中slack 取最小的
            slack[y] = t;
    }
    return 0;
}
开发者ID:Vstural,项目名称:ACM,代码行数:22,代码来源:KM算法.cpp

示例4: DFS

//************factorization part function***************
void DFS(int u)
{
	int v,i,h,temp,j=0;
	int rootlist[n];

	//initialize rootlist
	for(i=0;i<n;i++)
		rootlist[i]=0;

	if( cal_Qy_zero(u) )
			output_message_poly(u);     
	else if( deg[u] < (k-1) )		// the "D" of thesis represent k-1
	{
		//try n field element to calculate the y-root of Q(0,y)=0
		for(h=(n-1);h>=0;h--)		//field element from large to small
		{
			temp=cal_rootlist(u,h);
			if( temp == 0 )
			{	
				rootlist[j]=a[h];
				j++;
			}
		}

		for(i=0;i<n;i++)
			if( rootlist[i]!=0 )
			{
				v=time;
				time=time+1;
				last[v]=u;
				deg[v]=deg[u]+1;
				Coeff[v]=rootlist[i];
				cal_update_poly(v,u,rootlist[i]);  
				DFS(v);
			}

	}	

}
开发者ID:codywsy,项目名称:Simulation-by-C,代码行数:40,代码来源:unencode.cpp

示例5: maxMatch

int maxMatch() {
	for (int i = 0; i < N; ++i) used[i] = false;
	for (int i = 0; i < N; ++i) matchX[i] = -1;
	for (int i = 0; i < M; ++i) matchY[i] = -1;
	for (int i = 0; i < N; ++i) level[i] = -1;
	int match = 0, d;
	for ( ; ; match += d) {
		static int Q[MAXN * 2 + 1];
		int head = 0, tail = d = 0;
		for (int x = 0; x < N; ++x) level[x] = -1;
		for (int x = 0; x < N; ++x) if (matchX[x] == -1)
			level[x] = 0, Q[++tail] = x;
		while (head < tail)
			for (edge e(fir[x = Q[++head]]); e; e = e->next) {
				int y = e->to, z = matchY[y];
				if (z != -1 && level[z] < 0) level[z] = level[x] + 1, Q[++tail] = z;
			}
		for (int x = 0; x < N; ++x) used[x] = false;
		for (int x = 0; x < N; ++x) if (matchX[x] == -1) if (DFS(x)) ++d;
		if (d == 0) break;
	} return match;
}
开发者ID:bywbilly,项目名称:Templates,代码行数:22,代码来源:HopcroftKarp.cpp

示例6: solve

bool solve(int mid)
{
    top=0;
    memset(vert,0,sizeof(vert));
    memset(r_vert,0,sizeof(r_vert));
    for(int i=0;i<mid;i++)
    {
        Add_Edge(door[i][0],oppo[door[i][1]]);
        Add_Edge(door[i][1],oppo[door[i][0]]);
    }
    memset(v,0,sizeof(v));top=0;
    memset(order,0,sizeof(order));
    for(int i=0;i<2*n;i++)
        if(!v[i])DFS(i);
    memset(v,0,sizeof(v));top=1;
    memset(id,0,sizeof(id));
    for(int i=2*n-1;i>=0;i--)
        if(!v[order[i]]){RG_DFS(order[i]);top++;}
    for(int i=0;i<2*n;i++)
        if(id[i]==id[oppo[i]])return false;
    return true;
}
开发者ID:bigstupidx,项目名称:acm_problem_code,代码行数:22,代码来源:5630769_WA.cpp

示例7: main

main() {
    freopen("in.txt", "rt", stdin);  
    freopen("out2.txt", "w+t", stdout);
    clock_t st, ed;
    st = clock();
    int a, x;
	while(scanf("%d", &n) == 1) {
		for(a = 0; a < n; a++)
			next[a] = a+1;
		memset(Last, 0, sizeof(Last));
		memset(map, 0, sizeof(map));
		for(a = 1; a <= n; a++) {
			while(scanf("%d", &x) == 1 && x != 0)
				map[a][x-1] = 1;
		}
		next[n] = 0;
		DFS(n, 0);
	}
    ed = clock();
    /*printf("%f\n", (float)(ed - st )/CLOCKS_PER_SEC);*/
	return 0;
}
开发者ID:JohnXinhua,项目名称:UVa,代码行数:22,代码来源:快速排列.cpp

示例8: DFS

void DFS(int k) {
	if(k > len) return;
	if(DL[head].right == head) {
		if(k < len) len = k;
		return;
	}
	int t = Maxv, c, i, j;
	for(i = DL[head].right; i != head; i = DL[i].right) {
		if(s[i] < t) {
			t = s[i], c = i;
		}
	}
	remove(c);
	for(i = DL[c].down; i != c; i = DL[i].down) {
		for(j = DL[i].right; j != i; j = DL[j].right)
			remove(DL[j].ch);
		DFS(k+1);
		for(j = DL[i].left; j != i; j = DL[j].left)
			resume(DL[j].ch);
	}
	resume(c);
}
开发者ID:JohnXinhua,项目名称:UVa,代码行数:22,代码来源:dancinglink.cpp

示例9: if

Tarjan::Tarjan(Graph *graph)
{
	m_pre = 0;
	m_numSCC = 0;

	m_graph = graph;
	m_numNodes = graph->getNNodes();

	m_visited = new bool[graph->getNNodes()];
	m_sccGroupID = new int[graph->getNNodes()];
	m_low = new int[graph->getNNodes()];

	for (int i = 0; i < graph->getNNodes(); i++) 
	{	m_visited[i] = false;
		m_sccGroupID[i] = 0;
		m_low[i] = 0;
	}

	for (int i = 0; i < graph->getNNodes(); i++) 
	{	if (!m_visited[i]) DFS(graph, i);
	}
}
开发者ID:Onumis,项目名称:Motion-Graphs,代码行数:22,代码来源:Tarjan.cpp

示例10: main

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        top=-1;
        for(int i=1;i<=n;i++)vert[i]=r_vert[i]=NULL;
        for(int i=1;i<=n;i++)
        {
            int j;
            while(scanf("%d",&j),j) Add_Edge(i,j);
        }
        top=1;
        memset(visit,0,sizeof(visit));
        for(int i=1;i<=n;i++)
            if(!visit[i])DFS(i);
        
        top=0;
        memset(visit,0,sizeof(visit));
        for(int i=n;i>0;i--)
            if(!visit[order[i]]){DFS_RG(order[i]);top++;}
        
        memset(in,0,sizeof(in));
        memset(out,0,sizeof(out));
        for(int i=1;i<=n;i++)
            for(edge *p=vert[i];p;p=p->next)
                if(id[i]!=id[p->to])
                    out[id[i]]++,in[id[p->to]]++;
        int m1=0,m2=0,m3=0;
        for(int i=0;i<top;i++)
        {
            if(in[i]==0&&out[i]==0)m3++;
            else if(!in[i])m1++;
            else if(!out[i])m2++;
        }
        printf("%d\n%d\n",m1+m3,m3+(m1>m2?m1:m2));
    }
    return 0;
}
开发者ID:bigstupidx,项目名称:acm_problem_code,代码行数:38,代码来源:5948177_WA.cpp

示例11: main

int main() {
	//freopen("in.txt", "r", stdin);
	int nca;
	scanf("%d", &nca);
	while (nca--) {
		int top = -1;
		memset(vert, 0, sizeof (vert));
		scanf("%d%d", &n, &m);
		for (int x, y, i = 0; i < m; i++) {
			scanf("%d%d", &x, &y);
			add_edge(x, y, top);
			add_edge(y, x, top);
		}
		memset(dep, 0, sizeof (dep));
		memset(anc, 0, sizeof (anc));
		memset(par, -1, sizeof (par));
		memset(color, 0, sizeof (color));
		for (int i = 1; i <= n; i++) {
			if (!color[i])DFS(i, -1, 1);
		}
		memset(anc, 0, sizeof (anc));
		for (int ii, i = 1; i <= n; i++) {
			ii = my_find(i);
			anc[ii]++;
		}
		int ans = 0;
		for (int ii, i = 1; i <= n; i++) {
			ii = my_find(i);
			int tem = anc[ii];
			if (ans < tem) {
				ans = tem;
			}
		}
		if (ans == 1)ans = 0;
		printf("%d\n", ans);
	}
	return 0;
}
开发者ID:bigstupidx,项目名称:acm_problem_code,代码行数:38,代码来源:7374201_WA.cpp

示例12: main

int main() 
{
    FILE* fp = fopen("DFS.txt", "r"); 

    int vertex_num; 
    ADJACENT_LIST graph;  

    fscanf(fp, "%d\n", &vertex_num); 

    int tmp; 
    int i; 
    for(i = 1; i <= vertex_num; ++i) {

        fscanf(fp, "%d", &tmp); 
        graph[i] = (NODE)malloc(sizeof(struct node)); 
        NODE node_p = graph[i]; 
        node_p->data = tmp; 
        node_p->next = NULL; 

        while(tmp != -1) {
           
            fscanf(fp, "%d", &tmp); 
            node_p->next = (NODE)malloc(sizeof(struct node)); 
            node_p = node_p->next; 
            node_p->data = tmp; 
            node_p->next = NULL; 
        }
    }

    fclose(fp); 

    freopen("DFS.out", "w", stdout); 
    result = NULL; 

    DFS(graph, vertex_num); 

    return 0; 
}
开发者ID:cheerayhuang,项目名称:BOOK_ITA,代码行数:38,代码来源:DFS.c

示例13: main

int main(void)
{
    int n;
    printf("How many vertices you want to take?");
    scanf("%d",&n);
    initialize(n);
    insertEdges(n);
    DFS(n);
    sortVertices(n);
    checker = 1;
    initialize(n);
    reverseDirection(n);
    for(int i = 1; i <= n; i++)
    {
        int v = s_vertices[i];

        if(color[v] == 0)
        {
            c = 0;
            DFS_Visit(n, v);
            for(int j = 1; j <= c; j++)
            {
                if(j == 1)
                {
                    printf("%d ", ver[j]);
                }
                else{

                    printf(", %d",ver[j]);
                }
            }
            printf("\n");
        }
    }


return 0;
}
开发者ID:ParthoShuvo,项目名称:Algorithm-Lab,代码行数:38,代码来源:Strongly+Connected+Components.cpp

示例14: main

int
main(int argc, char **argv)
{
        int i = 0, j = 0;
        int blank = 0;

        while (1) {
                /* read input
                 */
                scanf("%d%d", &N, &L);
                for (i = 0; i < N; i++)
                        for (j = 0; j < N; j++)
                                scanf("%d", &G[i][j]);

                /* initialize
                 */
                len = 0, flag = 0;
                memset(visit, 0, sizeof(visit));
                path[0] = 1;
                visit[0] = 1;

                /* generate output
                 */
                if (blank)
                        putchar('\n');
                blank = 1;
                DFS(0);
                if (flag == 0)
                        printf("no walk of length %d\n", L);

                /* get rid of -9999
                 */
                if (scanf("%d", &i) == EOF)
                        break;
        }

        return 0;
}
开发者ID:chenrushan,项目名称:uva,代码行数:38,代码来源:677_all_walks_length_n.c

示例15: save

void save(pos p[]){
	int j;
	pos zero;
	zero.x=0;
	zero.y=0;
	if(step+DIS>=50){
			answer=1;
	} else {
		for(j=0;j<num;j++){		
					//	printf("The distance is :%lf \n",distance(zero,p[j]));
			if(visited[j]==0 && distance(zero,p[j]) <= DIS+step){
				answer=DFS(p,j);
			if(answer==1)
				break;
						}	
	
					}
	}
	if(answer==1)
		printf("Yes");
	else
		printf("No");
}
开发者ID:whmrtm,项目名称:DataStructure-C,代码行数:23,代码来源:hw5-2.c


注:本文中的DFS函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。