社区讨论
说句闲话:我发现了一种新的存图方式
学术版参与者 24已保存回复 58
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 58 条
- 当前快照
- 1 份
- 快照标识符
- @lz0kdhyk
- 此快照首次捕获于
- 2024/07/25 08:57 2 年前
- 此快照最后确认于
- 2024/07/25 09:27 2 年前
为大家奉上用它写的一个小程序(打印邻接表):
CPP#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
struct edge{
int t,u;
};
struct/* node*/{
int u,c;
int rn,cn;
edge x[maxn],y[maxn];
}g[maxn];
void addedge(int s,int t,int u){
g[s].y[g[s].cn++]={t,u};
g[t].x[g[t].rn++]={s,u};
}
void allnb(int a){
for(int i=0;i<g[a].cn;i++){
cout<<g[a].y[i].t<<" "<<g[a].y[i].u<<endl;
}
cout<<endl;
}
int main(){
int n,p;
cin>>n>>p;
for(int i=0;i<n;i++){
cin>>g[i].c>>g[i].u;
}
for(int i=0;i<p;i++){
int a,b,c;
cin>>a>>b>>c;
addedge(a,b,c);
}
for(int i=0;i<n;i++){
allnb(i);
}
}
本蒟蒻觉得这是最直观的一种方式,因为他直接用数组模拟链式关系。
回复
共 58 条回复,欢迎继续交流。
正在加载回复...