CF 187C Weak Memory 优先队列 难度:2
http://codeforces.com/problemset/problem/187/C
这道题可以用二分+dfs检测,或者优先队列解
此处用了优先队列解法
从起点出发,维护一个优先队列,内容是pair<当前所需最小容量,节点序号>,则每一次取出的都一定是最小容量,也就是说结果必然大于等于这个容量
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
typedef pair<int ,int >P;
priority_queue<P,vector<P>,greater<P> > que;
const int maxn=1e5+5;
const int maxm=4e5+5;
const int inf=0x7fffffff; int n,m,k,s,e;
bool g[maxn];
int cap[maxn]; int first[maxn];
int nxt[maxm];
int to[maxm]; void add(int f,int t,int ind){
nxt[ind]=first[f];
first[f]=ind;
to[ind]=t;
}
int main(){
scanf("%d%d%d",&n,&m,&k);
fill(cap,cap+n+1,inf);
memset(first,-1,sizeof(first));
for(int i=0;i<k;i++){
int guide;
scanf("%d",&guide);
g[guide]=true;
} for(int i=0;i<m;i++){
int f,t;
scanf("%d%d",&f,&t);
add(f,t,2*i);
add(t,f,2*i+1);
}
scanf("%d%d",&s,&e); int ans=0;
cap[s]=0;
que.push(P(0,s));
while(!que.empty()){
int c=que.top().first,f=que.top().second;que.pop();
if(c>cap[f])continue; ans=max(ans,c);
if(f==e)break; if(g[f])c=0;
for(int p=first[f];p!=-1;p=nxt[p]){
if(cap[to[p]]>c+1){
cap[to[p]]=c+1;
que.push(P(c+1,to[p]));
}
}
} printf("%d",cap[e]==inf?-1:ans);
return 0;
}
CF 187C Weak Memory 优先队列 难度:2的更多相关文章
- UVA LA 3983 - Robotruck DP,优先队列 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 【codeforces】【比赛题解】#849 CF Round #431 (Div.2)
cf的比赛越来越有难度了……至少我做起来是这样. 先看看题目吧:点我. 这次比赛是北京时间21:35开始的,算是比较良心. [A]奇数与结束 "奇数从哪里开始,又在哪里结束?梦想从何处起航, ...
- Method and apparatus for providing total and partial store ordering for a memory in multi-processor system
An improved memory model and implementation is disclosed. The memory model includes a Total Store Or ...
- simotion读写CF卡,保存/读取变量
simotion读写CF卡功能 1 使用西门子的Simotion运动控制器时,有时需要用到 读/写 CF卡的功能.主要来自以下几个方面的需求. 1)用户数据量较大,可保持(retain)存储区的容量不 ...
- Memory Ordering in Modern Microprocessors
Linux has supported a large number of SMP systems based on a variety of CPUs since the 2.0 kernel. L ...
- Memory Barriers Are Like Source Control Operations
From: http://preshing.com/20120710/memory-barriers-are-like-source-control-operations/ If you use ...
- memory ordering 内存排序
Memory ordering - Wikipedia https://en.wikipedia.org/wiki/Memory_ordering https://zh.wikipedia.org/w ...
- MySQL · 引擎特性 · InnoDB 同步机制
前言 现代操作系统以及硬件基本都支持并发程序,而在并发程序设计中,各个进程或者线程需要对公共变量的访问加以制约,此外,不同的进程或者线程需要协同工作以完成特征的任务,这就需要一套完善的同步机制,在Li ...
- Android 性能优化(20)多核cpu入门:SMP Primer for Android
SMP Primer for Android 1.In this document Theory Memory consistency models Processor consistency CPU ...
随机推荐
- koa2+mongoose搭建框架模型
由于学的是java,所以此框架多少有点java的影子,我觉得不必排斥语言,只要思想好,所有语言均可以通用.项目分以下几层 app.js项目启动入口,类似于main函数 controller-view层 ...
- 64. Minimum Path Sum(最小走棋盘 动态规划)
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- hdu1403 Longest Common Substring
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1403 题目: Longest Common Substring Time Limit: 800 ...
- 【1】Kali Linux的安装及配置
爱生活就得够GEEK. ---------------------------------------------------------------完美的分割线------------------- ...
- 使用.NET Core和Vue搭建WebSocket聊天室
博客地址是:https://qinyuanpei.github.io. WebSocket是HTML5标准中的一部分,从Socket这个字眼我们就可以知道,这是一种网络通信协议.WebSocket是 ...
- MyEclipse 2014优化设置(禁用myeclipse updating indexes)
1.指定本机java环境 Windows-->preferences-->java-->Insetallel JREs 右侧 单击ADD standard VM-->Next ...
- centos安装xdebug 和 phpstorm+Xdebug断点调试PHP
转载地址:http://www.2cto.com/os/201304/206058.html CentOS下安装xdebug 在CentOS 6.x 的系统中,是集成xdebug 的, y ...
- 机器学习:让我们彻底搞懂CNN【转】
本文转载自:http://115.com/182920/T1266078.html 机器学习:让我们彻底搞懂CNN 上世纪科学家们发现了几个视觉神经特点,视神经具有局部感受眼,一整张图的识别由多个局部 ...
- db2 xml 转 table
版本:DB2 Version 9.1 1.创建测试表,初始化数据 create table emp (doc XML); INSERT INTO EMP VALUES ('<dept bldg= ...
- Spring boot 解决 hibernate no session异常
启动类中加入 @Beanpublic OpenEntityManagerInViewFilter openEntityManagerInViewFilter(){ return new OpenEnt ...