邻接表是图的一种最主要的存储结构,对图上的每一个点建立一个容器,用来储存每个顶点的所有邻接点以及距离。
下面的是一个简单的模板
///邻接表
#include<stdio.h>
#include<vector>
#include<iostream>
using namespace std;
const int maxn=100005;
struct Edge///节点的定义
{
int to,dis;
Edge(int t,int d){
to=t;
dis=d;
}
};
vector<Edge> g[maxn];
void Addedge(int u,int v,int val)
{
g[u].push_back(Edge(v,val));
}