只集成了最基本的功能。。也就是加边和取相邻点。
1 struct Graph{ 2 int n, m, cntedge; 3 int fir[maxn]; 4 Edge link[maxn]; 5 Edge edge[maxm]; 6 7 void init(int nodenum, int edgenum){ 8 n=nodenum, m=edgenum; 9 } 10 11 Graph(){ 12 memset(fir, 0, sizeof(fir)); 13 memset(edge, 0, sizeof(edge)); 14 cntedge=0; 15 n=0; 16 m=0; 17 return; 18 } 19 20 void addedge(int x, int y, int v){ 21 ++cntedge; 22 edge[cntedge].to=y; 23 edge[cntedge].v=v; 24 edge[cntedge].next=fir[x]; 25 fir[x]=cntedge; 26 return; 27 } 28 29 Edge *get_link(int x){ 30 int cnt=0; 31 for (int nowedge=fir[x]; nowedge; 32 nowedge=edge[nowedge].next){ 33 link[++cnt]=edge[nowedge]; 34 } 35 link[0].v=cnt; 36 return link; 37 } 38 39 };
时间: 2024-11-07 03:08:49