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 ...
随机推荐
- Extjs 正则表达式 常用的
extjs正则表达式验证 2011年10月10日 10:36:05 阅读数:7305 在EXT中使用正则表达式验证的方法:fieldLabel : '员工号',name : 'employee.e ...
- linux下创建用户,给用户设置密码,给用户授权
1.linux下的用户是属于组的,所以需要创建一个组,划分给用户.创建命令: 在root下执行 groupadd ver 创建一个组ver 2.创建用户 useradd ...
- Laravel 学习记录
1.当配置 根目录没有指向/public 时 去掉www.blog.im/public 后的文件 需要把 public 文件夹里的..htaccess 文件放到 项目根目录.server.ph ...
- python之yield
#!/usr/bin/env python# -*- coding:utf-8 -*-# Author:wadeson '''def foo(): print("-------------- ...
- 20145321 《Java程序设计》课程总结
20145321 <Java程序设计>课程总结 读书笔记链接汇总 第一周读书笔记 第二周读书笔记 第三周读书笔记 第四周读书笔记 第五周读书笔记 第六周读书笔记 第七周读书笔记 第八周读书 ...
- RS232引脚,RS485引脚
1.RS232引脚 2.RS485引脚
- keras安装配置指南【linux环境】【转】
本文转载自:https://keras-cn.readthedocs.io/en/latest/for_beginners/keras_linux/#kerasmnist 本教程不得用于任何形式的商业 ...
- 如何退出minicom【学习笔记】
一.先按ctr+a进入设置模式 二.在按x退出
- 设置iframe内表单target属性以兼容IE、Firefox【转载】
设置iframe内表单target属性以兼容IE.Firefox[转载] 2011年11月19日 haibor 今天有客户反应,在一产品网站的资源下载页面,用户登录提交后页面无反应! 经测 ...
- windows环境下mysql的解压安装以及备份和还原
系统环境为server2012 1.下载mysql解压版,解压安装包到指定目录 2.在以上目录中,复制一份my-default.ini文件,重命名为my.ini,进行如下修改(按照需要): [mysq ...