用vector存图
代码语言:javascript复制const int N=1e5 10;
vector<int> G[N];
void addedge(int u,int v){
G[u].push_back(v);
G[v].push_back(u);
}
用vector存图(有边权)
代码语言:javascript复制const int N=1e5 10;
struct Edge{
int v,w;
};
Edge make_Edge(int v,int w){
Edge cur;cur.v=v;cur.w=w;return cur;
}
vector<Edge> G[N];
void addedge(int u,int v,int w){
G[u].push_back(make_Edge(v,w));
G[v].push_back(make_Edge(u,w));
}
Pair:
vector<pair<int,int> >G[N];
void addedge(int u,int v,int w){
G[u].push_back(make_pair(v,w));
G[v].push_back(make_pair(u,w));
}