之间都是用vector模拟邻接表,但是后面发现vector时间复杂度有点高,所以写了份用数组模拟链表的方法实现邻接表
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
/******************/
#define LL long long
const int maxn=100010;
template<int N,int M>
struct Graph
{
int top;
struct Vertex
{
int head;
}V[N];
struct Edge
{
int v,next;
}E[M];
void init()
{
memset(V,-1,sizeof V);
top=0;
}
void add_edge(int u,int v,int w)
{
E[top].v=v;
E[top].next=V[u].head;
V[u].head=top++;
}
};
Graph<maxn,maxn> g;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
g.init();
}
return 0;
}