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的更多相关文章

  1. UVA LA 3983 - Robotruck DP,优先队列 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  2. 【codeforces】【比赛题解】#849 CF Round #431 (Div.2)

    cf的比赛越来越有难度了……至少我做起来是这样. 先看看题目吧:点我. 这次比赛是北京时间21:35开始的,算是比较良心. [A]奇数与结束 "奇数从哪里开始,又在哪里结束?梦想从何处起航, ...

  3. 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 ...

  4. simotion读写CF卡,保存/读取变量

    simotion读写CF卡功能 1 使用西门子的Simotion运动控制器时,有时需要用到 读/写 CF卡的功能.主要来自以下几个方面的需求. 1)用户数据量较大,可保持(retain)存储区的容量不 ...

  5. 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 ...

  6. Memory Barriers Are Like Source Control Operations

    From:   http://preshing.com/20120710/memory-barriers-are-like-source-control-operations/ If you use ...

  7. memory ordering 内存排序

    Memory ordering - Wikipedia https://en.wikipedia.org/wiki/Memory_ordering https://zh.wikipedia.org/w ...

  8. MySQL · 引擎特性 · InnoDB 同步机制

    前言 现代操作系统以及硬件基本都支持并发程序,而在并发程序设计中,各个进程或者线程需要对公共变量的访问加以制约,此外,不同的进程或者线程需要协同工作以完成特征的任务,这就需要一套完善的同步机制,在Li ...

  9. Android 性能优化(20)多核cpu入门:SMP Primer for Android

    SMP Primer for Android 1.In this document Theory Memory consistency models Processor consistency CPU ...

随机推荐

  1. 优化css,增加性能

    转载自:https://www.cnblogs.com/xiaoloulan/p/5801663.html 前端性能优化一直是一个比较热门的话题,我们总是在尽我们最大的努力去,提高我们的页面性能,比如 ...

  2. hihocoder1478 水陆距离

    地址:http://hihocoder.com/problemset/problem/1478 题目: 水陆距离 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个 ...

  3. Jmeter使用流程及简单分析监控(转载)

    转载自:https://www.cnblogs.com/linglingyuese/archive/2013/03/04/linglingyuese-one.html#undefined 一.安装Jm ...

  4. ansible playbook基本操作

    一.ansible playbook简单使用 相当于是把模块写入到配置文件里面 vim /etc/ansible/test.yml //写入如下内容: --- - hosts: 127.0.0.1 r ...

  5. 【Linux学习】2.Linux常见命令行

    记录学习Linux 系统的相关知识点,欢迎大家拍砖交流,一起成长:QQ:2712192471 作者背景:前端开发工程师 | Python | web安全爱好者   Linux命令行: 系统关机重启 s ...

  6. python3_pickle模块详解

    python3 pickle持久化的储存数据. python程序运行中得到了一些字符串,列表,字典等数据,想要长久的保存下来,方便以后使用,而不是简单的放入内存中关机断电就丢失数据.python模块大 ...

  7. 20145331《Java程序设计》第5周学习总结

    20145331<Java程序设计>第5周学习总结 教材学习内容总结 第八章 概述 Java异常机制主要依赖于try.catch.finally.throw.throws五个关键字. 语法 ...

  8. 网络攻防工具介绍——Metasploit

    Metasploit 简介 Metasploit是一款开源的安全漏洞检测工具,可以帮助安全和IT专业人士识别安全性问题,验证漏洞的缓解措施,并管理专家驱动的安全性进行评估,提供真正的安全风险情报.这些 ...

  9. Leetcode(93): Restore IP Addresses

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  10. 微信JS-SDK接口,分享到朋友圈”按钮点击状态及自定义分享内容接口

    jssdk.php 接口文件class JSSDK { private $appId; private $appSecret; public function __construct($appId, ...