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

想开一个做网站的公司长治网站制作怎么做

想开一个做网站的公司,长治网站制作怎么做,大型网站二次开发方案,上海关键词排名推广文章目录 1. 题目来源2. 题目解析 1. 题目来源 链接:743. 网络延迟时间 相关链接: [图最短路模板] 五大最短路常用模板) 2. 题目解析 怎么讲呢,挺抽象的…很久没写最短路算法了。反正也是写出来了,但脱离了模板,把…

文章目录

    • 1. 题目来源
    • 2. 题目解析

1. 题目来源

链接:743. 网络延迟时间

相关链接:

  • [图+最短路+模板] 五大最短路常用模板)

2. 题目解析

怎么讲呢,挺抽象的…很久没写最短路算法了。反正也是写出来了,但脱离了模板,把自己还给绕进去了…

这块还是按照模板来写吧。

至于具体的算法思想,看相关链接即可。


  • 时间复杂度 O ( n m ) O(nm) O(nm)
  • 空间复杂度 O ( 1 ) O(1) O(1)

标准 spfa

class Solution {
public:int networkDelayTime(vector<vector<int>>& times, int n, int k) {vector<pair<int, int>> g[n + 1];for (auto& e : times) {int x = e[0], y = e[1], w = e[2];g[x].push_back({y, w});}// 标准 spfa 算法queue<int> q; vector<int> dist(n + 1, 1e9);   // 注意这里初始化的是最大值vector<bool> st(n + 1, false);q.push(k);dist[k] = 0;while (q.size()) {auto x = q.front(); q.pop();st[x] = false; // x 不在队列中for (auto& [y, w] : g[x]) { // 更新 x 点临边if (dist[y] > dist[x] + w) { // 如果 y 点可以被 x 点更新dist[y] = dist[x] + w; // 则更新if (!st[y]) { // 如果 y 不在队列中,则加入q.push(y);st[y] = true;}}}}int res = -1e9;for (int i = 1; i <= n; i ++ ) {if (dist[i] == 1e9) return -1;  // 这里也是拿最大值进行的判断res = max(res, dist[i]);}return res;}
};

以下是 y 总写的 spfa 模板,大同小异。

const int N = 110, M = 6010, INF = 0x3f3f3f3f;
int h[N], e[M], w[M], ne[M], idx;
int dist[N];
bool st[N];class Solution {
public:void add(int a, int b, int c) {e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;}void spfa(int start) {queue<int> q;q.push(start);memset(dist, 0x3f, sizeof dist);dist[start] = 0;while (q.size()) {int t = q.front();q.pop();st[t] = false;for (int i = h[t]; ~i; i = ne[i]) {int j = e[i];if (dist[j] > dist[t] + w[i]) {dist[j] = dist[t] + w[i];if (!st[j]) {q.push(j);st[j] = true;}}}}}int networkDelayTime(vector<vector<int>>& times, int n, int k) {memset(h, -1, sizeof h);idx = 0;for (auto& e: times) {int a = e[0], b = e[1], c = e[2];add(a, b, c);}spfa(k);int res = 1;for (int i = 1; i <= n; i ++ ) res = max(res, dist[i]);if (res == INF) res = -1;return res;}
};作者:yxc
链接:https://www.acwing.com/activity/content/code/content/1011633/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

2024年11月26日00:08:57
这里不知道随便写的 spfa 也过了…
不要留下坏印象…

class Solution {
public:int networkDelayTime(vector<vector<int>>& times, int n, int k) {vector<vector<pair<int, int>>> g(n, vector<pair<int, int>>{});for (auto& e : times) {int x = e[0] - 1, y = e[1] - 1, w = e[2];g[x].push_back({y, w});}queue<int> q; vector<int> st(n, -1);  // 即是 st 又是 dist,用 -1 做状态标记位k = k - 1;q.push(k);st[k] = 0;while (q.size()) {auto x = q.front(); q.pop();for (auto& [y, w] : g[x]) {if (st[y] == -1 || st[y] > st[x] + w) { // 这里其实参考的是 dij 算法,又像 spfast[y] = st[x] + w;q.push(y);}}}int res = -1e9;for (int& x : st) {if (x == -1) return -1;res = max(res, x);}return res;}
};
http://www.yayakq.cn/news/57390/

相关文章:

  • 做网站基础源代码杭州九鸿科技网站开发
  • 怎么建公司网站教程老闵行
  • 郑州做网站企业超碰网站正在建设中
  • 高端网站开发有哪些常州网络公司网站
  • 网站维护升级访问中古典网站建设
  • 企业网站模板网 凡建站阿里云个人网站建设
  • 阳泉市编办网站三基建设网站后台登录不进去
  • 电子商务是干嘛的 主要学什么kj6699的seo综合查询
  • 深圳网站建设培训机构商家怎样入驻微信小程序
  • 张家港网站建设做网站官网制作需要多少钱
  • 二级区域网站名刷数据网站怎么推广
  • 邢台网站改版定制应用开发是什么
  • 做企业网站需要的人怎么把网站扒下来
  • 苏州市住房城乡建设局网站app网站开发报价
  • 奥运会网站制作深圳 倡导居家办公
  • 用dw建立网站国企网站建设
  • 怎么用网站源码做网站钓鱼网站在线下载
  • 营销型网站建设怎么做营销网站建设4399游戏大全
  • 外贸建站行业好做吗厦门市建设局报表网站
  • 专门做办公的网站绍兴做网站选哪家
  • 蝶山网站建设一级做爰片a视频网站4
  • 酒店网站规划建设方案书wordpress 安桌应用
  • 犀牛云做网站哪些做网站的公司
  • 品牌推广方案设计大连网站优化公司
  • 南充网站设计门户网站的营销方式
  • 大型网站团队人数如何进行域名备案
  • 网站制作学校建站方案策划书
  • 网站开发与维护专业破解wordpress的密码
  • 做网站 前途网站开发者yotoon
  • 个人网站也要备案吗网站你的后台管理系统用什么做