bzoj:3392: [Usaco2005 Feb]Part Acquisition 交易
Description
Input
Output
Sample Input
1 3
3 2
2 3
3 1
2 5
5 4
Sample Output

#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std; struct na{
int y,ne;
na(){
ne=;
}
};
int n,k,a,l[],r[],x,y,dis[],i;
na b[];
queue <int> q;
char cc;
int read(){
int a=;
cc=getchar();
while(cc<''||cc>'') cc=getchar();
while(cc>=''&&cc<='') a=a*+cc-,cc=getchar();
return a;
}
int main(){
n=read();k=read();
for (i=;i<=n;i++){
x=read();y=read();
if (l[x]==) l[x]=i;else b[r[x]].ne=i;
r[x]=i;b[i].y=y;
}
for (i=;i<=k;i++) dis[i]=;
q.push();dis[]=;
while(!q.empty()){
int p=q.front();
for (i=l[p];i;i=b[i].ne){
if (dis[b[i].y]==){
if (b[i].y==k){
printf("%d",dis[p]+);
return ;
}
dis[b[i].y]=dis[p]+;
q.push(b[i].y);
}
}
q.pop();
}
printf("-1");
}
bzoj:3392: [Usaco2005 Feb]Part Acquisition 交易的更多相关文章
- 【BZOJ】3392: [Usaco2005 Feb]Part Acquisition 交易(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=3392 同1674 #include <cstdio> #include <cstr ...
- BZOJ3392: [Usaco2005 Feb]Part Acquisition 交易
3392: [Usaco2005 Feb]Part Acquisition 交易 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 26 Solved: ...
- BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )
最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...
- bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛
1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Description Farmer John has built a new long barn, with N ...
- [BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】
题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cs ...
- BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机
Description 约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T ...
- bzoj:1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
Description It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of wh ...
- bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛【二分+贪心】
二分答案,贪心判定 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...
- BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 网络流 + 二分答案
Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...
随机推荐
- cocoapods安装说明,最快安装,以及使用
安装卸载更新新推荐 文章最后 其他问题总结: 1 添加taobao提供的镜像地址:http://ruby.taobao.org/ 移除命令:gem sources --remove https://r ...
- js验证input输入框(字母,数字,符号,中文)
[javascript]代码库 <h1>js验证输入框内容</h1> <br /> <br /> 只能输入英文 <input type=" ...
- 关于ubuntu下qt编译显示Cannot connect creator comm socket /tmp/qt_temp.xxx/stub-socket的解决办法
今天在ubuntu下安装了qtcreator,准备测试一下是否能用,果然一测试就出问题了,简单编写后F5编译在gnome-terminal中出现 Cannot connect creator comm ...
- @Data 注解引出的 lombok 小辣椒
今天在看代码的时候, 看到了这个注解, 之前都没有见过, 所以就查了下, 发现还是个不错的注解, 可以让代码更加简洁. 这个注解来自于 lombok,lombok 能够减少大量的模板代码,减少了在使用 ...
- MySQL连接方式及大小写问题
一.连接数据库 在命令行连接MySQL有这两种方式,一种是使用命令行参数:另一种是将参数信息写入配置文件 1.命令行中使用参数 -u用户名 -p密码 -D数据库名 -P数据库服务端口 -s安静模式 ...
- Oracle学习笔记_10_判断是否为日期类型
FUNCTION isdate (datestr VARCHAR2, format VARCHAR2) RETURN number IS p_date DATE; BEGIN SELECT TO_DA ...
- CSS3 转换2D transform
Transform字面上就是变形,改变的意思.在CSS3中transform主要包括以下几种:旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix.下面我们一 ...
- parse_str 与 http_build_query的使用
1 http_build_query() 使用 生成 URL-encode 之后的请求字符串 [建议在使用前,使用array_filter($query) 进行处理] 例子 1. http_build ...
- 朴素的treap
所谓Treap,就是一种二叉查找树,而我们知道二叉查找树,相对来说比较容易形成最坏的链表情况,所以我们有一种数据结构来防止二叉查找树出现最坏情况,那就是Treap. Treap=tree+heap,T ...
- chromedriver与chrome版本映射列表
chromedriver与chrome版本映射列表: chromedriver版本 支持的Chrome版本 v2.30 v58-60 v2.29 v56-58 v2.28 v55-57 v2.27 v ...