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. 『NiFi 自定义 Processor 无法获取到 Logger』问题解决

    一.概述 自定义的 Processor 继承了 AbstractProcessor,而 AbstractProcessor 继承了 AbstractSessionFactoryProcessor ,g ...

  2. 2017 Multi-University Training Contest - Team 3 Kanade's sum hd6058

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6058 题目: Kanade's sum Time Limit: 4000/2000 MS (J ...

  3. hihocoder1478 水陆距离

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

  4. Lucene.Net 3.0.3如何从TokenStream中获取token对象

    Lucene.Net最高版本为3.0.3,并且apache已经不再提供Lucene.Net的更新,没仔细研究过Lucene.Net的所有版本,Lucene.Net3.0.3遍历TokenStream获 ...

  5. 资产证券化(ABS)+ 特殊目的信托(SPV)

    资产证券化是指以基础资产未来所产生的现金流为偿付支持,通过结构化设计进行信用增级,在此基础上发行资产支持证券(Asset-backed Securities, ABS)的过程,通过将有形或者无形资产作 ...

  6. C++ 第三十三天

    Ⅰ.类成员函数的隐式参数 T *const this . 就是说对于某个类的成员函数 returnType function() 的真实面目其实是这样的 returnType function(T * ...

  7. ArrayList原理分析(重点在于扩容)

    首先,ArrayList定义只定义类两个私有属性: /** * The array buffer into which the elements of the ArrayList are stored ...

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

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

  9. 如何退出minicom【学习笔记】

    一.先按ctr+a进入设置模式 二.在按x退出

  10. 采用OpenReplicator解析MySQL binlog

    Open Replicator是一个用Java编写的MySQL binlog分析程序.Open Replicator 首先连接到MySQL(就像一个普通的MySQL Slave一样),然后接收和分析b ...