图邻接表数组存储
来源:互联网 发布:日语汉字注音软件 编辑:程序博客网 时间:2024/06/05 04:28
#include<iostream>#include<algorithm>#include<string.h>using namespace std;int cnt = 0 ;int head[100010]; struct st{int u;int v;int w;int next;}edge[100010];void add(int u, int v, int w){edge[cnt].u = u;edge[cnt].v = v;edge[cnt].w = w;edge[cnt].next = head[u];head[u] = cnt++;}int main(){int n,m,u,v,w;memset(head,-1,sizeof(head));cin>>n;for (int i=0; i<n; i++){cin>>u>>v>>w;add(u,v,w);} cin>>m;for (int i=head[m]; i!=-1; i=edge[i].next){cout<<edge[i].u<<"->"<<edge[i].v<<":"<<edge[i].w<<endl; }return 0;}如果是无向图的话在添加一次add(v,u,w);即可
阅读全文
0 0
- 图邻接表数组存储
- 使用数组存储邻接表
- 邻接表存储图
- 数据结构之图-邻接表、及指针数组,链式存储
- 使用数组来模拟邻接表存储图信息
- 图的存储结构(邻接矩阵、边数组、邻接表、十字链表、邻接多重表)
- 图的邻接表存储
- 图的邻接表存储
- 图的邻接表存储
- 图的存储-邻接表
- 图的邻接表存储
- 图的邻接表存储
- 图的邻接表存储
- 图的邻接表存储
- 图的邻接表存储
- 图的邻接表存储
- 图的邻接表存储
- 图(网)的存储结构(数组存储表示即邻接矩阵、邻接表)
- 000032:将两个数相加的结果输出
- 两个有序链表序列的合并 PAT
- Xcode下载低版本iOS系统模拟器进行调试
- 恶补系列之操作系统——内核态与用户态
- c语言数据类型及printf
- 图邻接表数组存储
- SQLite学习手册(实例代码<一>)
- docker service create error
- Java-jsp表单提交整个table数据到后台
- 浏览器后退刷新
- snv服务器备份方案
- 两个时间相比,只精确到天以上,忽略时分秒
- 个人推荐的Python 书籍
- hihocoder 1055 刷油漆 (树型dp)