链式前向星

链式前向星是一种高效存储图结构的方法,相较于邻接表,其常数更小,能避免在竞赛编程中因常数过大导致超时。本文介绍了链式前向星的实现细节,包括加边操作的关键代码,并推荐了一个视频资源,帮助理解这一概念。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <math.h>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include<functional>
#include<time.h>
#include<stdlib.h>
#include<time.h>
#include <climits>
using namespace std;
const int maxn = 1e6;
map<char, int >mp;
int a[100010][12];
struct Edge{
    int to, next, w;
}edge[maxn];
int head[maxn];
int cnt;
void intit()
{
    cnt = 0;
    for (int i = 0; i < maxn; i++)
    {
        edge[i].next = -1;
        head[i] = -1;
    }

}

void add(int u, int v, int w)
{
    edge[cnt].to = v;
    edge[cnt].w = w;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}
void add(int u, int v, int w)
{
    edge[cnt].to = v;
    edge[cnt].w = w;
    edge[cnt].next = head[u];
    head[u] = cnt++;
}
int main(){
   

    return 0;
}

关于链式前向星,其实就是一个数组模拟链表的过程,既然我们已经学会了vector的邻接表的存图,为什么还要去学链式前向星?其实是邻接表的常数略大,容易在题目中被卡常。链式前向星最巧妙的部分其实就在加边的最后两列代码。转载bilibili 的up主视频,这应该是我看过最友好的解释了。
https://www.bilibili.com/video/BV1mJ411S7BB?from=search&seid=1970747121682435324

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值