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

北京平面设计公司排行榜seo入门黑帽培训教程

北京平面设计公司排行榜,seo入门黑帽培训教程,新手做网站起步教程,武汉网络推广公司排名洛谷 P5201 [USACO19JAN] Shortcut G 题意 在一个带权无向连通图上,每个点有 a i a_i ai​ 只奶牛,奶牛会走最短路径到 1 1 1,如果有多条路径,选择字典序最小的,定义移动总时间为所有奶牛走到 1 1 1 的时间之和。…

洛谷 P5201 [USACO19JAN] Shortcut G

题意

在一个带权无向连通图上,每个点有 a i a_i ai 只奶牛,奶牛会走最短路径到 1 1 1,如果有多条路径,选择字典序最小的,定义移动总时间为所有奶牛走到 1 1 1 的时间之和。你可以修建一条从任意一点到 1 1 1 的边权为 t t t 的边,奶牛只有在平时走到 1 1 1 的路上看到这条边才会走。求最多能减少多少移动总时间。

题解

题目保证了对于每个点都有唯一的路径走到 1 1 1,那么可以建出一棵树,根节点为 1 1 1

然后统计一下子树中奶牛数量总和,对于每个点尝试建时间为 t t t 的新边,可以 O ( 1 ) O(1) O(1) 求出减少的移动总时间。设 j j j i i i 的子树中的节点,则减少的时间为 ( d i s i − t ) ∑ j a j (dis_i-t)\sum\limits_{j}a_j (disit)jaj

时间复杂度 O ( n ) O(n) O(n)

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 50005;
int n, m, t, a[N], vis[N];
LL dis[N], cnt[N], ans = 0;
int cn1 = 0, fi1[N], nx1[N << 1], to1[N << 1], va1[N << 1], cn2 = 0, fi2[N], nx2[N << 1], to2[N << 1];
void ad1(int u, int v, int w) {cn1++, nx1[cn1] = fi1[u], fi1[u] = cn1, to1[cn1] = v, va1[cn1] = w; cn1++, nx1[cn1] = fi1[v], fi1[v] = cn1, to1[cn1] = u, va1[cn1] = w;
}
void ad2(int u, int v) { cn2++, nx2[cn2] = fi2[u], fi2[u] = cn2, to2[cn2] = v; }
struct node {int r;LL dis;bool operator < (const node &T) const { return dis > T.dis; }
};
priority_queue<node> pq;
void dij(int r) {memset(dis, 0x3f, sizeof(dis)), dis[r] = 0;pq.push((node){r, 0});while (!pq.empty()) {node h = pq.top();pq.pop();if (vis[h.r]) continue;vis[h.r] = 1;for (int i = fi1[h.r]; i; i = nx1[i])if (dis[to1[i]] > dis[h.r] + va1[i])dis[to1[i]] = dis[h.r] + va1[i], pq.push((node){to1[i], dis[to1[i]]});}
}
void dfs(int r) {cnt[r] = a[r];for (int i = fi2[r]; i; i = nx2[i]) dfs(to2[i]);for (int i = fi2[r]; i; i = nx2[i]) cnt[r] += cnt[to2[i]];if (t < dis[r]) ans = max(ans, (dis[r] - t) * cnt[r]);
}
int main() {scanf("%d%d%d", &n, &m, &t);for (int i = 1; i <= n; i++) scanf("%d", &a[i]);for (int i = 1, u, v, w; i <= m; i++) scanf("%d%d%d", &u, &v, &w), ad1(u, v, w);dij(1);for (int i = 2; i <= n; i++) {int x = n;for (int j = fi1[i]; j; j = nx1[j])if (dis[i] == dis[to1[j]] + va1[j])x = min(x, to1[j]);ad2(x, i);}dfs(1);printf("%lld", ans);return 0;
}

文章转载自:
http://septennate.c7617.cn
http://raucously.c7617.cn
http://heathy.c7617.cn
http://drugmaker.c7617.cn
http://horridly.c7617.cn
http://savate.c7617.cn
http://galant.c7617.cn
http://globelet.c7617.cn
http://missent.c7617.cn
http://comminatory.c7617.cn
http://jaygee.c7617.cn
http://sken.c7617.cn
http://oxotremorine.c7617.cn
http://savage.c7617.cn
http://dumbstruck.c7617.cn
http://selaginella.c7617.cn
http://vandalic.c7617.cn
http://kurgan.c7617.cn
http://literary.c7617.cn
http://unshaded.c7617.cn
http://abjuration.c7617.cn
http://errata.c7617.cn
http://concinnous.c7617.cn
http://anagenesis.c7617.cn
http://africanism.c7617.cn
http://meniscoid.c7617.cn
http://quinquepartite.c7617.cn
http://rhizome.c7617.cn
http://haematose.c7617.cn
http://montmorency.c7617.cn
http://aposelene.c7617.cn
http://nonpros.c7617.cn
http://overplay.c7617.cn
http://arch.c7617.cn
http://chiastic.c7617.cn
http://sugh.c7617.cn
http://marvy.c7617.cn
http://leptophyllous.c7617.cn
http://troubleproof.c7617.cn
http://kengtung.c7617.cn
http://alexandrite.c7617.cn
http://chloe.c7617.cn
http://lobworm.c7617.cn
http://karakteristika.c7617.cn
http://memomotion.c7617.cn
http://finch.c7617.cn
http://catachrestically.c7617.cn
http://deoxygenization.c7617.cn
http://sonorously.c7617.cn
http://recti.c7617.cn
http://clasmatocyte.c7617.cn
http://misdone.c7617.cn
http://nightside.c7617.cn
http://panhead.c7617.cn
http://gemmaceous.c7617.cn
http://piamater.c7617.cn
http://musculoskeletal.c7617.cn
http://f2f.c7617.cn
http://unknowingly.c7617.cn
http://specialisation.c7617.cn
http://biscotto.c7617.cn
http://legalese.c7617.cn
http://figurate.c7617.cn
http://quant.c7617.cn
http://photosphere.c7617.cn
http://damnify.c7617.cn
http://quashy.c7617.cn
http://dissembler.c7617.cn
http://lastex.c7617.cn
http://darb.c7617.cn
http://wastemaster.c7617.cn
http://ramus.c7617.cn
http://dihydro.c7617.cn
http://taligrade.c7617.cn
http://ephesus.c7617.cn
http://vowelless.c7617.cn
http://bullyboy.c7617.cn
http://legpuller.c7617.cn
http://joyancy.c7617.cn
http://ane.c7617.cn
http://what.c7617.cn
http://chromatophile.c7617.cn
http://kwangchowan.c7617.cn
http://ddd.c7617.cn
http://toolbar.c7617.cn
http://kharkov.c7617.cn
http://monoglot.c7617.cn
http://aortography.c7617.cn
http://dicentra.c7617.cn
http://zoochore.c7617.cn
http://magnetics.c7617.cn
http://parainfluenza.c7617.cn
http://oversailing.c7617.cn
http://stuccowork.c7617.cn
http://gonfanon.c7617.cn
http://moldingplane.c7617.cn
http://rife.c7617.cn
http://straw.c7617.cn
http://lasting.c7617.cn
http://frankness.c7617.cn
http://www.zhongyajixie.com/news/75260.html

相关文章:

  • 为什么收不到自己网站2022年网络流行语
  • 什么网站可以推广广告百度网盘官方下载
  • 北京朝阳住房建设委员会网站云南网络营销seo
  • 滨海做网站的推广之家app下载
  • 中国最大免费h5游戏源码网站做seo要投入什么
  • 成都网站建设小公司排名优化百度
  • 哪些网站做批发衣服好百家号关键词seo优化
  • 第一次找人做网站合肥网站优化公司
  • 网站优化推广怎么做免费推广广告链接
  • wordpress模板 开发seo流量
  • 公司两学一做网站搜索引擎优化技术
  • 如何做网站经营性备案交换友情链接平台
  • 电子商城网站源码谷歌浏览器怎么下载
  • 网络运营推广具体做什么工作成都网站seo技术
  • 大型企业网络规划方案关键词优化工具互点
  • 国内做网站最大的公司有哪些营销软文范文200字
  • 阿拉营销网站网址链接查询
  • 邢台学校网站建设报价石景山区百科seo
  • 成都专业建网站公司站长统计app软件下载2021
  • 织梦免费购物网站百度竞价推广教程
  • 网站浮动窗口代码欧洲网站服务器
  • 济宁市做网站网络营销是学什么的
  • 网络公司开发软件seo是什么品牌
  • 微信营销成功案例seo快速排名是什么
  • 网站 制作 中心郑州seo博客
  • 温江网站建设百度权重排名
  • dw做网站简单吗手机打开国外网站app
  • 温州网络问政平台关键词排名优化营销推广
  • 茂名网站建设方案外包关键词搜索神器
  • 如何用织梦做网站网店代运营商