有关vector的存图用法

用vector存图

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存图(有边权)

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));
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
03-15 10:59
已编辑
爱写代码的菜code...:哎,自己当时拿到字节offer的时候也在感叹终于拿到了,自己当时最想去的企业就是字节,结果还是阴差阳错去了鹅厂。祝uu一切顺利!!!
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务