2022.5.10模拟(关于存图方式的小总结)(链式前向星)

今天T3挂掉了。

裸的 dijkstra,但是边数最大可达1e6,所以我可爱的vector挂掉了(悲)。

Conclusion:对于稠密图(m >= 1e6 or less?)滚去用链前

链前代码:

const int N = 1e5,M = 1e6 + 5;
struct qwq{
    int from,to,nxt,w;
    qwq(int a,int b,int c,int d):from(a),to(b),nxt(c),w(d){}
    qwq(){}
}e[M];//无向图e[M<<1]
int cnt,head[N];
inline void add(int u,int v,int w){
    e[++cnt] = qwq(u,v,head[u],w);
    head[u] = cnt;
}

vector存图及遍历:

const int N = 1e5,M = 1e6 + 5;
typedef pair<int,int> pir;
#define mp make_pair
#define pb push_back
vector<pir>g[N];
inline void add(int u,int v,int w){
    g[u].pb(mp(v,w));    
}
//存储
for(pir tmp : g[u]){
    int v = tmp.first,w = tmp.second;    
}
//总之就是for(vector存的类型 变量名 : 遍历的vector容器名)
//就会自动遍历这个容器里的每一个元素了,从前往后。

 

posted @ 2022-05-11 11:59  Xu_brezza  阅读(34)  评论(2编辑  收藏  举报