优美的链式前向星
来源:互联网 发布:php oa 开源 编辑:程序博客网 时间:2024/05/16 06:57
首先贴上一份贴别好的blog详细的介绍了链式前向星的全过程:
链式前向星
贴上一份板子:
#include <bits/stdc++.h>using namespace std;const int maxn = 4e5+100;struct node{ int to, next, weight;}edge[maxn];int cnt;int head[maxn];int n;void add(int u, int v, int weight){ edge[cnt].to = v; edge[cnt].weight = weight; edge[cnt].next = head[u]; head[u] = cnt++;}int main(){ while(cin>>n){ cnt=0, memset(head, -1, sizeof(head)); for(int i=0; i<n-1; i++){ int u, v, weight; cin>>u>>v>>weight; add(u, v, weight); add(v, u, weight); } for(int i=1; i<=n; i++){ for(int j=head[i]; j!=-1; j = edge[j].next){ cout<<edge[j].to<<" "; } cout<<endl; } } return 0;}
阅读全文
0 0
- 优美的链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- 链式前向星
- FreeSWITCH加载非默认模块
- hdu1404 博弈
- k近邻理论与实践
- UE4学习笔记22th:配置游戏模式
- 二叉树实例
- 优美的链式前向星
- 数据结构 图的遍历 C语言版
- ImageJ 综述
- HTTP 协议入门
- hql/sql语句查询英文字符时是不区分大小写的
- Android应用组件之加载器(Loader)
- 数据结构 图的建立 C语言版
- 素数距离问题
- 王爽 《汇编语言》 读书笔记 七 更灵活段定位内存地址段方法