您当前的位置: 首页 > 

先求一个导

暂无认证

  • 3浏览

    0关注

    291博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

abc237 E(spfa已死)

先求一个导 发布时间:2022-02-05 17:32:54 ,浏览量:3

题目 题意: 给定n个点的点权值hi,m条边。规定有向边(u,v)的边权为 hu - hv (hu > hv) -2(hu - hv) (hu < hv) 0 (hu = hv) 求点1到其他点的最长路。 思路: 所有边取反然后spfa跑最短路,赛后加强数据以后就不行了。考虑用Dij跑最短路,把所有边取反,但是有负边权,需要换一种建图方式。把所有诸如的(u,v)边都加上 h[u] + h[v].这样就没有负边权了。自己推一下对于势能的影响。 p’ = p + (h[st] - h[ed]). 在这里插入图片描述 时间复杂度: O(nlogm) 代码:

// Problem: E - Skiing
// Contest: AtCoder - AtCoder Beginner Contest 237
// URL: https://atcoder.jp/contests/abc237/tasks/abc237_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;i            
关注
打赏
1662037414
查看更多评论
0.0364s