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 ...
随机推荐
- 关于使用Xcode9.0使用[UIImage imageNamed:]返回null的问题
最近升级Xcode9.0,没少折腾,再加上iOS11出现的问题,又要适配一些奇怪的问题.这都没啥,但是如果Xcode出问题,那问题可真是难找.因为习惯的操作潜意思的告诉自己这样做是不会错的. 在Xco ...
- verilog抓外部低频输入信号的上升沿和下降沿
版权申明:本文为博主窗户(Colin Cai)原创,欢迎转帖.如要转贴,必须注明原文网址 http://www.cnblogs.com/Colin-Cai/p/7220107.html 作者:窗户 Q ...
- openstack操作之二 restful api
Restful api 是openstack各服务调用的接口,简单理解为可以通过网络去调用的函数.postman是一款前端调用工具,测试后端接口的时候往往是使用该工具去验证.在openstack的使用 ...
- nova创建虚拟机源码分析系列之三 PasteDeploy
上一篇博文介绍WSGI在nova创建虚拟机过程的作用是解析URL,是以一个最简单的例子去给读者有一个印象.在openstack中URL复杂程度也大大超过上一个例子.所以openstack使用了Past ...
- lesson - 2 yum /单用户/救援模式/Linux 启动
课程大纲:1. yum使用yum 是一个在线安装软件包的工具,它可以帮我们解决软件包的依赖,这个日后会详细介绍.我们介绍了以下几个用法:yum list 这个命令可以列出所有安装过和未安装的软 ...
- centos7 卸载home 扩大root空间
=============================================== 2017/11/1_第1次修改 ccb_warlock == ...
- spring boot 遇到 supported setting property http://xml.org/sax/properties/lexical-handler
解决链接:http://apache-fop.1065347.n5.nabble.com/org-xml-sax-SAXNotSupportedException-thrown-by-FOP-td11 ...
- js必须掌握的基础
好多人想要学习前端……自学或者培训那么我们在学习过程中到底需要掌握那些基础知识呢!下面分类了JS中必备的知识也是必须要了解学会的!看一看你是否已经将JS的基础知识都了如指掌了呢? 事件: onmous ...
- Django__RBAC
RBAC : 基于角色的权限访问控制(Role-Based Access Control) RBAC 模型作为目前最为广泛接受的权限模型 角色访问控制(RBAC)引入了Role的概念,目的是为了隔离U ...
- [js高手之路]原型式继承与寄生式继承
一.原型式继承本质其实就是个浅拷贝,以一个对象为模板复制出新的对象 function object( o ){ var G = function(){}; G.prototype = o; retur ...