扒的vector
来源:互联网 发布:网络p2p理财排行 编辑:程序博客网 时间:2024/04/29 21:58
原文
#include <vector>
#include <algorithm>#include <cstring>
#include <cstdio>
#include <iterator>
#include <iostream>
#include <queue>
#define print(a) cout << #a << " : " << a << endl
using namespace std;
struct node
{
int v;
int w;
node(){}
node(int v, int w):v(v), w(w){}
};
vector<node> vc[1000];
bool vis[100];
void dfs(int cur) //深度遍历
{
cout << cur << " "; //访问cur节点
for(int i = 0; i < vc[cur].size(); i++)
{
int v = vc[cur][i].v;
if(vis[v] == false)
{
vis[v] = true;
dfs(v);
}
}
}
void out_deg(int vexNum) //求每一个点的出度
{
for(int i = 1; i <= vexNum; i++)
{
cout << i << " ' out_deg is : " << vc[i].size() << endl;
}
}
void bfs() //广度优先遍历
{
queue<node> q;
q.push(node(1, 0));
while(!q.empty())
{
node top = q.front(); q.pop();
cout << top.v << " "; //访问top节点
for(int i = 0; i < vc[top.v].size(); i++)
{
int v = vc[top.v][i].v;
int w = vc[top.v][i].w;
if(vis[v] == false)
{
vis[v] = true;
q.push(node(v, w));
}
}
}
}
void test(int vexNum)
{
out_deg(vexNum);cout << endl;
vector<node>::iterator it;
for(it = vc[3].begin(); it != vc[3].end(); NULL) //删除点3 后面接的点5这条边
{
if(5 == (*it).v)
it = vc[3].erase(it); //注意删除后it指向下一个点, 所以必须这样
else
it++;
}
for(int i = 1; i <= vexNum; i++) //输出没个点所能到达的边
{
cout << i << "--->: ";
for(int j =0; j < vc[i].size(); j++)
cout << vc[i][j].v << " ";
cout << endl;
}
memset(vis, false, sizeof(vis));
dfs(1);cout << endl;
memset(vis, false, sizeof(vis));
bfs();cout << endl;
}
int main()
{
int vexNum, edgeNum;
cin >> vexNum >> edgeNum;
for(int i = 0; i < edgeNum; i++)
{
int u, v, w;
cin >> u >> v >> w;
vc[u].push_back(node(v, w));
}
test(vexNum);
return 0;
}
0 0
- 扒的vector
- 扒扒我的微信朋友圈
- 套残理员呢?弹簧的游扒
- 扒扒这些年学过的编程语言
- 扒掉Smarty的裤衩儿
- 企鹅扒了中移动的内裤
- 【源码】网上随意扒的源码
- 扒光tp后的一些感想
- 扒来的mac快捷键总会
- 扒谱大杂烩-都是前辈写的
- 如何扒出Momentum的背景
- 防止你的代码被扒
- 邮箱扒头像来告诉你怎么写简单的脚本扒图
- 邮箱扒头像来告诉你怎么写简单的脚本扒图
- 扒扒在异国他乡有着不为人知艳遇史的女星(图)
- 推荐一款很好用的一款扒网站的工具
- 推荐一款很好用的一款扒网站的工具
- 我也是扒在玻璃上的蝇子?
- jQuery选择器之表单元素选择器
- 服务端监控方案
- torch 命令行
- LCA问题----RMQ算法
- 活动的启动模式
- 扒的vector
- PE文件详解(六)
- QML中ListView-GridView等对象的数据模型更新详解
- 正则表达式
- 书中的题目 j_10
- 文章标题
- 关于解决从浏览器输入中文,经过web容器解析到达servlet中来出现的乱码问题
- Windows 上 .NET Core 的先决条件
- 练习