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 ...
随机推荐
- 【JMeter】获取json响应报文中数组长度
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.Predicate; import net.minidev.json.J ...
- java 设计模式-缺省适配器模式
本文转载地址:http://www.cnblogs.com/iyangyuan/archive/2013/03/11/2954808.html 在程序设计过程中,读者很可能遇到这样一种困境:设计了一个 ...
- 606. Construct String from Binary Tree
You need to construct a string consists of parenthesis and integers from a binary tree with the preo ...
- 让 kibana 后台启动的方案
为了解决启动kibana后关闭shell终端kibana自动关闭的问题,记录2种解决方案,试验后均可行. 假设kibana安装的目录为 /usr/local/kibana/ 方案一: 使用nohup ...
- Django2中文文档--目录及介绍部分
Django2文档-文档结构 我是按照官方文档的格式进行翻译,所以格式根官方格式一致 如果大家发现哪些地方有问题可以联系我 2426525089@qq.com 或者加入QQ群跟我一起翻译,群号码: 2 ...
- maven 打包Could not resolve dependencies for project和无效的目标发行版: 1.8
1.maven 打包Could not resolve dependencies for project 最近项目上使用的是idea ide的多模块话,需要模块之间的依赖,比如说系统管理模块依赖授权模 ...
- 尤克里里 ukulele 单板 非kaka tom uma
本店冲人气优惠,不搞倒闭之类的事 23寸尤克里里 单板 单板 单板 彩贝镶边演出大气 单板 单板 单板 彩贝镶边演出大气 单板 单板 单板 彩贝镶边演出大气 配件选购40元全套(加棉琴包.金属变调夹. ...
- 利用USearch去除嵌合体(chimeras)
嵌合体序列指在pcr过程中,两条不同的序列产生杂交扩增的序列,属于人工污染,在ITS和16S分析中,应该首先去除,USearch提供去除嵌合体的功能 usearch -uchime_ref reads ...
- jQuery 文档操作方法 (四)
方法 描述 addClass() 向匹配的元素添加指定的类名. after() 在匹配的元素之后插入内容. append() 向匹配元素集合中的每个元素结尾插入由参数指定的内容. appendTo() ...
- word-break: break-word; 文本溢出
word-break: break-word; 中文汉字不会溢出,英文字母会溢出 这个时候添加属性 word-break: break-word; 即可 使得 不溢出 ======== ...