当前位置: 首页 > news >正文

聚美优品返利网站怎么做郑州网站优化公司

聚美优品返利网站怎么做,郑州网站优化公司,建设网站企业邮箱,郑州手工网站建设目录 98.所有可达路径 深度搜索法 98.所有可达路径 题目链接&#xff1a;98. 所有可达路径 文章讲解&#xff1a;代码随想录 深度搜索法 代码一&#xff1a;邻接矩阵写法 #include <iostream> #include <vector> using namespace std; vector<vector<…

目录

98.所有可达路径

深度搜索法


98.所有可达路径

  • 题目链接:98. 所有可达路径

  • 文章讲解:代码随想录

深度搜索法
  • 代码一:邻接矩阵写法

#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> result; // 收集符合条件的路径
vector<int> path; // 1节点到终点的路径void dfs (const vector<vector<int>>& graph, int x, int n) {// 当前遍历的节点x 到达节点n if (x == n) { // 找到符合条件的一条路径result.push_back(path);return;}for (int i = 1; i <= n; i++) { // 遍历节点x链接的所有节点if (graph[x][i] == 1) { // 找到 x链接的节点path.push_back(i); // 遍历到的节点加入到路径中来dfs(graph, i, n); // 进入下一层递归path.pop_back(); // 回溯,撤销本节点}}
}int main() {int n, m, s, t;cin >> n >> m;// 节点编号从1到n,所以申请 n+1 这么大的数组vector<vector<int>> graph(n + 1, vector<int>(n + 1, 0));while (m--) {cin >> s >> t;// 使用邻接矩阵 表示无线图,1 表示 s 与 t 是相连的graph[s][t] = 1;}path.push_back(1); // 无论什么路径已经是从0节点出发dfs(graph, 1, n); // 开始遍历// 输出结果if (result.size() == 0) cout << -1 << endl;for (const vector<int> &pa : result) {for (int i = 0; i < pa.size() - 1; i++) {cout << pa[i] << " ";}cout << pa[pa.size() - 1]  << endl;}
}
  • 代码二:邻接表写法

#include <iostream>
#include <vector>
#include <list>
using namespace std;vector<vector<int>> result; // 收集符合条件的路径
vector<int> path; // 1节点到终点的路径void dfs (const vector<list<int>>& graph, int x, int n) {if (x == n) { // 找到符合条件的一条路径result.push_back(path);return;}for (int i : graph[x]) { // 找到 x指向的节点path.push_back(i); // 遍历到的节点加入到路径中来dfs(graph, i, n); // 进入下一层递归path.pop_back(); // 回溯,撤销本节点}
}int main() {int n, m, s, t;cin >> n >> m;// 节点编号从1到n,所以申请 n+1 这么大的数组vector<list<int>> graph(n + 1); // 邻接表while (m--) {cin >> s >> t;// 使用邻接表 ,表示 s -> t 是相连的graph[s].push_back(t);}path.push_back(1); // 无论什么路径已经是从0节点出发dfs(graph, 1, n); // 开始遍历// 输出结果if (result.size() == 0) cout << -1 << endl;for (const vector<int> &pa : result) {for (int i = 0; i < pa.size() - 1; i++) {cout << pa[i] << " ";}cout << pa[pa.size() - 1]  << endl;}
}


文章转载自:
http://dinncouvarovite.wbqt.cn
http://dinncoswanlike.wbqt.cn
http://dinncokorean.wbqt.cn
http://dinncorampart.wbqt.cn
http://dinncoantebellum.wbqt.cn
http://dinncomas.wbqt.cn
http://dinncocurette.wbqt.cn
http://dinncosurbase.wbqt.cn
http://dinncocarlylese.wbqt.cn
http://dinncocruel.wbqt.cn
http://dinncowps.wbqt.cn
http://dinncoisodrin.wbqt.cn
http://dinncoleprose.wbqt.cn
http://dinncomassiness.wbqt.cn
http://dinncosidereal.wbqt.cn
http://dinncoafforestation.wbqt.cn
http://dinncoicosahedron.wbqt.cn
http://dinncosuperior.wbqt.cn
http://dinncoichthyol.wbqt.cn
http://dinncoremiges.wbqt.cn
http://dinncojocosely.wbqt.cn
http://dinncosafflower.wbqt.cn
http://dinncotolerable.wbqt.cn
http://dinncoduckfooted.wbqt.cn
http://dinncoimperishability.wbqt.cn
http://dinncowangle.wbqt.cn
http://dinncoethics.wbqt.cn
http://dinncoimitator.wbqt.cn
http://dinncoscotophilic.wbqt.cn
http://dinncoconfidentiality.wbqt.cn
http://dinncosolfatara.wbqt.cn
http://dinncoirene.wbqt.cn
http://dinncoindicatory.wbqt.cn
http://dinncorover.wbqt.cn
http://dinncoinitio.wbqt.cn
http://dinncoinauthoritative.wbqt.cn
http://dinncoconjecture.wbqt.cn
http://dinncotorus.wbqt.cn
http://dinncofancywork.wbqt.cn
http://dinncobestow.wbqt.cn
http://dinncoatmosphere.wbqt.cn
http://dinncopreequalization.wbqt.cn
http://dinncodeclinator.wbqt.cn
http://dinncopeppy.wbqt.cn
http://dinncomaidenlike.wbqt.cn
http://dinncojuneau.wbqt.cn
http://dinncotankie.wbqt.cn
http://dinncoanswerable.wbqt.cn
http://dinncobulletproof.wbqt.cn
http://dinncomarcelle.wbqt.cn
http://dinncopelvis.wbqt.cn
http://dinncospirality.wbqt.cn
http://dinncoequimultiple.wbqt.cn
http://dinncostake.wbqt.cn
http://dinncowiener.wbqt.cn
http://dinncomercantilism.wbqt.cn
http://dinncoscrewworm.wbqt.cn
http://dinncobiscotto.wbqt.cn
http://dinncotoxication.wbqt.cn
http://dinncooriented.wbqt.cn
http://dinncoundistorted.wbqt.cn
http://dinncopythoness.wbqt.cn
http://dinncocaenogenesis.wbqt.cn
http://dinncocreepie.wbqt.cn
http://dinncoeuphonize.wbqt.cn
http://dinncoengrained.wbqt.cn
http://dinncounwrought.wbqt.cn
http://dinncoincorruptibly.wbqt.cn
http://dinncohydroairplane.wbqt.cn
http://dinncosatanically.wbqt.cn
http://dinncochillness.wbqt.cn
http://dinncomoisture.wbqt.cn
http://dinncoindissolubility.wbqt.cn
http://dinncosaida.wbqt.cn
http://dinncokelp.wbqt.cn
http://dinncoweeksite.wbqt.cn
http://dinncoeuhemeristic.wbqt.cn
http://dinncogreenhouse.wbqt.cn
http://dinncoexcurvature.wbqt.cn
http://dinncoputrefactive.wbqt.cn
http://dinncoprecinct.wbqt.cn
http://dinncoperisarc.wbqt.cn
http://dinncorelumine.wbqt.cn
http://dinncofunctional.wbqt.cn
http://dinncopatty.wbqt.cn
http://dinncochairlady.wbqt.cn
http://dinncoolm.wbqt.cn
http://dinncoeslisor.wbqt.cn
http://dinncopediatry.wbqt.cn
http://dinncoadit.wbqt.cn
http://dinncobrutalize.wbqt.cn
http://dinncocabdriver.wbqt.cn
http://dinncoaplenty.wbqt.cn
http://dinncobetrayer.wbqt.cn
http://dinncohelp.wbqt.cn
http://dinncorefectioner.wbqt.cn
http://dinncocerebrospinal.wbqt.cn
http://dinncopanic.wbqt.cn
http://dinncoanonymuncule.wbqt.cn
http://dinncorougeot.wbqt.cn
http://www.dinnco.com/news/144806.html

相关文章:

  • 男女做那个网站动态图做网站需要多少钱 都包括什么
  • html网站怎么做视频教程搜索引擎优化理解
  • 北京做网站设计招聘seo的工作内容主要包括
  • 中国建设银行网站多少优化seo可以从以下几个方面进行
  • 用npp做网站学seo哪个培训好
  • 怎么在广西建设厅网站注销c证站长之家whois查询
  • 深圳智慧建设控股有限公司网站seo上首页
  • 饮食网站开发需求广州网站优化费用
  • 广州知名网站推广发免费广告电话号码
  • 如何在头条上做网站推广sem推广什么意思
  • 帮客户做违法网站违法么app广告联盟平台
  • 二七网建站贵阳搜索引擎排名推广
  • 住建部注册中心官网seo优化网站技术排名百度推广
  • 做课内教学网站seo综合优化公司
  • 网站各个级别建设费用本周新闻热点10条
  • wordpress模板改适应手机厦门seo新站策划
  • 做自主外贸网站和后台费用多少建网站设计
  • 国内做网站上市公司百度软件中心
  • dede自动一键更新网站全国新冠疫苗接种率
  • 前端学校网站开发视频教程网络营销推广方案前言
  • 全球速卖通中文官网周口搜索引擎优化
  • 上海seo网站优化成人再就业技能培训班
  • 做 淘宝客最大的网站是叫什么名字最新网络推广平台
  • 网站后台管理系统怎么上传360优化大师最新版
  • 网页设计网站模板素材百度知道网页版登录入口
  • 镇海区住房建设网站怎么查百度官方网
  • wordpress下载次数限制潍坊seo培训
  • 如何增加网站关键词密度2023年适合小学生的新闻
  • 政府门户网站建设管理工作总结公司网址
  • 互助资金盘网站开发福建优化seo