码迷,mamicode.com
首页 > 其他好文 > 详细

向前星

时间:2019-01-16 22:45:55      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:eof   实现   div   class   push   ack   方法   font   const   

一下两种方法掌握一种即可

一.前向星建图

/**
/*向前星 
/*@Victor 
*/
const int MX = 1e5 +5;
const int ME = 2e5 + 5;

struct edge{
    int v ,w ;
    int nxt;
    
    edge(){}
    edge(int _v, int _w,int _nxt){
        v = _v; 
        w = _w;
        nxt  = _nxt;
    }
    
}E[ME];
int head[MX], tot;
void init(){
    memset(head , -1;sizeof(head));
    tot = 0;
} 

void add_edge(int u ,int v,int w){
    E[tot] = edge(v ,w , head[u]);
    head[u] = tot++;
}

二.vector建图

/**
/*vector实现向前星
/*@author Victor 
*/

const int MX = 1e5 + 5;

struct edge {
    int v, w , nxt;
    edge() {}
    edge(int _v, int _w){
        v = _v;
        w = _w;
        nxt = _nxt;
    }
    
};

vector<edge>E[MX];
void init(int n){
    for(int i = 0;i <= n; i++){
        E[i].clear();
    }
}

void add_edge(int u, int v,int w){
    E[u].push_back(edge(v,w));
}

 

向前星

标签:eof   实现   div   class   push   ack   方法   font   const   

原文地址:https://www.cnblogs.com/DWVictor/p/10279616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!