当前位置: 首页> 财经> 访谈 > web网站开发基本流程有哪些_免费的html_2021最火营销方案_品牌推广

web网站开发基本流程有哪些_免费的html_2021最火营销方案_品牌推广

时间:2025/8/28 5:58:08来源:https://blog.csdn.net/qq_61552256/article/details/142901399 浏览次数:0次
web网站开发基本流程有哪些_免费的html_2021最火营销方案_品牌推广

今天入门图论的基本理论,做了深度优先遍历图的例子


797.所有可能的路径

题目链接

解题过程

  • 用dfs遍历每一个边

力扣

class Solution {
public:vector<vector<int>>result;vector<int>path;void dfs(vector<vector<int>>& graph) {if (path.back() == graph.size() - 1) {result.push_back(path);return;}int points = path.back();for (int point : graph[points]) {path.push_back(point);dfs(graph);path.pop_back();}}vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {path.push_back(0);dfs(graph);return result;}
};

ACM

#include<iostream>
#include<vector>
#include<list>
using namespace std;
int n, m;
vector<vector<int>>result;
vector<int>path;
void dfs(vector<list<int>>&graph) {if (path.back() == n) {result.push_back(path);return;}int point = path.back();for (int i : graph[point]) {path.push_back(i);dfs(graph);path.pop_back();}
}int main() {cin >> n >> m;vector<list<int>>graph(n + 1);while (m--) {int s, t;cin >> s >> t;graph[s].push_back(t);}path.push_back(1);dfs(graph);if (result.size() == 0) cout << -1 << endl;for (vector<int>vec : result) {for (int i = 0; i < vec.size() - 1; i++) {cout << vec[i] << " ";}cout << vec.back() << endl;}
}
关键字:web网站开发基本流程有哪些_免费的html_2021最火营销方案_品牌推广

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: