Demo entry 6361058

a

   

Submitted by a on May 03, 2017 at 09:09
Language: C++. Code size: 472 Bytes.

//存储结构
struct Edge
{
    int to;  //边的终点
    int w;   //边的权值
    int next; //起点相同的下一条边
}edge[M];   //M为边数,N为顶点数
int head[N]; //head[i]是以i为起点的第一条边的编号
int cnt;  //记录边数
//初始化
cnt=0;
memset(head,-1,sizeof(head));
//建图
void addEdge(int u,int v,int w)
{
    edge[cnt].to=v;
    edge[cnt].w=w;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}
//遍历以u为起点的邻接边
for(int i=head[u];i!=-1;i=edge[i].next){
    int to=edge[i].to; //终点
    int w=edge[i].w;   //权值
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).