zoukankan      html  css  js  c++  java
  • 链式前向星DFS

    本文链接:http://www.cnblogs.com/Ash-ly/p/5399057.html

    采用链式前向星存图的DFS:

    #include <iostream>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <algorithm>
    #include <queue>
    using namespace std;
    typedef long long LL;
    
    const int maxN = 100 + 3;
    const int maxM = 1000 + 3;
    int head[maxN];
    int visited[maxN];
    int N, M;
    
    struct EdgeNode
    {
        int to;
        int w;
        int next;
    };
    EdgeNode Edges[maxM];
    
    void DFS(int x)
    {
        visited[x] = 1; //标记当前节点已被访问
        for(int i = head[x]; i != -1; i = Edges[i].next)
        {
        //对于每个未被访问的相邻节点,调用DFS,遍历结束后、尝试其他支路
            if( !visited[Edges[i].to] )
                DFS(Edges[i].to);
        }
    }
    
    int main()
    {
        freopen("input.txt", "r", stdin);
        memset(head, -1, sizeof(head));
        cin >> N >> M;
        for(int i = 1; i <= M; i++)
        {
            int x, y ,z;
            cin >> x >> y >> z;
            Edges[i].to = y;
            Edges[i].w = z;
            Edges[i].next = head[x];
            head[x] = i;
        }
        memset(visited, 0, sizeof(visited));
        DFS(1);
        return 0;
    }
  • 相关阅读:
    程序优化
    obsidium 重定位
    Obsidium V1.3.0.4 脱壳
    SEH 栈溢出
    DWORD SHOOT
    两种堆表学习
    修改网页转向
    WireShark过滤语法
    获取系统信息学习
    怎么在 渗透无键盘 查询机
  • 原文地址:https://www.cnblogs.com/Ash-ly/p/5399057.html
Copyright © 2011-2022 走看看