博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[SPFA]JZOJ 5869 绿洲
阅读量:7219 次
发布时间:2019-06-29

本文共 1108 字,大约阅读时间需要 3 分钟。

Description

 

Input

Output

 

Sample Input

5 7 22 31 21 31 42 43 43 54 5

Sample Output

1 2 2 1 2
 

Data Constraint

 

Hint

分析

显然我们对于每个绿洲求spfa即可

(为什么我dij堆优化炸了????)

 

#include 
#include
#include
#include
using namespace std;const int N=1e5+10;struct Edge { int v,nx;}g[2*N];int cnt,list[N],d[N],ans[N];bool b[N],gr[N];int n,m,k;void Add(int u,int v) { g[++cnt].v=v;g[cnt].nx=list[u];list[u]=cnt;}void Spfa(int v0) { int cnt=1,sum=0; deque
q; while (!q.empty()) q.pop_front(); memset(d,0x3f,sizeof d);memset(b,0,sizeof b); q.push_back(v0); d[v0]=0;b[v0]=1; while (!q.empty()) { int u=q.front();q.pop_front(); if (d[u]*cnt>sum) { q.push_back(u); continue; } cnt--;sum-=d[u]; for (int i=list[u];i;i=g[i].nx) if (d[g[i].v]>d[u]+1) { d[g[i].v]=d[u]+1; if (!b[g[i].v]) { if (!q.empty()&&d[g[i].v]
View Code

 

转载于:https://www.cnblogs.com/mastervan/p/9650796.html

你可能感兴趣的文章
hdu 3804 Query on a tree (树链剖分+线段树)
查看>>
定位、指南针、地理编码
查看>>
Kafka 简介
查看>>
MySQL 用户连接与用户线程
查看>>
RabbitMq、ActiveMq、Kafka和Redis做Mq对比
查看>>
C# 图片处理(压缩、剪裁,转换,优化)
查看>>
Linux bridge-utils tunctl 使用
查看>>
Leetcode Pascal's Triangle II
查看>>
运行shell脚本报错 '\357\273\277': command not found 解决的方法
查看>>
android studio 0.8.1使用和遇到问题解决
查看>>
云服务器ECS选购集锦之六区域选择帮助
查看>>
云虚机选购指南之二云虚拟主机试用帮助文档
查看>>
女友眼中的IT男
查看>>
Excel连接
查看>>
java基础-多线程学习
查看>>
WPF打印原理,自定义打印
查看>>
HTML5 5
查看>>
箭头css
查看>>
Python入门,以及简单爬取网页文本内容
查看>>
顺丰科技笔试回忆
查看>>