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 ...
随机推荐
- message from server: "Host '192.168.6.68' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts
系统或者程序连接数据报错 null, message from server: "Host '192.168.6.68' is blocked because of many connect ...
- 谷歌技术"三宝"之BigTable(转)
原文地址: http://blog.csdn.net/opennaive/article/details/7532589 2006年的OSDI有两篇google的论文,分别是BigTable和Ch ...
- 使用ubifs作为根文件系统的openwrt如何在进行sysupgrade时保存旧的配置
1.openwrt的默认方案(squashfs + jffs2) sysupgrade脚本直接调用default_do_upgrade更新设备树.内核.根文件系统,那么它是如何保存旧配置的呢?请看de ...
- mysql的空闲8小时问题
在spring中配置数据源时,必须设定destroy-method="close"属性,以便spring容器关闭时,数据源能正常关闭. 如果数据库时mysql,如果数据源配置不当, ...
- Numpy学习2
载入数据和保存数据 In [34]: arr = np.loadtxt("/home/hadoop/wujiadong/np.txt") In [35]: np.save(&quo ...
- 7.scala:继承
版权申明:转载请注明出处. 文章来源:http://bigdataer.net/?p=315 排版乱?请移步原文获得更好的阅读体验 类似于java中的继承,在scala中同样有继承一说,而且在很多方面 ...
- Zookeeper Zkclient客户端
Zkclient是对Zookeeper的原生API进行了包装,实现了超时重连.Watcher反复注册等功能,它可以实现递归创建,删除节点,但是zkClient不能递归给节点赋值. 主要的api如下: ...
- class.getResource()和getResourceAsStream的用法
转自:http://blog.csdn.net/lcj8/article/details/3502849 class.getResource()的用法 用JAVA获取文件,听似简单,但对于很多像我这样 ...
- 使用Github上传本地代码
最近在学习Python,但是每次写完代码后不知道该怎么跟家里的电脑进行同步.于是开始了学习github ,方法很简单 1:注册个git账号:https://github.com 2:本地安装git软件 ...
- redis——redis主从复制
和MySQL主从复制的原因一样,Redis虽然读取写入的速度都特别快,但是也会产生读压力特别大的情况.为了分担读压力,Redis支持主从复制,Redis的主从结构可以采用一主多从或者级联结构,Redi ...