vector建图简单直观,加边灵活,但占用内存大。

链式前向星建图比较容易操作。

链式前向星

int head[N],cnt;
struct Edge
{
    int next;
    int to;
    ll w;
    Edge(){memset(head,-1,sizeof head);}
}edge[N];
void addedge(int u,int v,ll w)
{
    edge[cnt].to=v;
    edge[cnt].next=head[u];
    edge[cnt].w=w;
    head[u]=cnt++;
}

vector

struct Edge
{
    int to;
    ll w;
};
vector<Edge>g[N];
void addedge(int u,int v,ll w)
{
    g[u].push_back({v,w});
}

  

 

相关文章:

  • 2021-10-05
  • 2022-12-23
  • 2021-08-08
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案