bzoj:1681 [Usaco2005 Mar]Checking an Alibi 不在场的证明
Description
A crime has been comitted: a load of grain has been taken from the barn by one of FJ's cows. FJ is trying to determine which of his C (1 <= C <= 100) cows is the culprit. Fortunately, a passing satellite took an image of his farm M (1 <= M <= 70000) seconds before the crime took place, giving the location of all of the cows. He wants to know which cows had time to get to the barn to steal the grain. Farmer John's farm comprises F (1 <= F <= 500) fields numbered 1..F and connected by P (1 <= P <= 1,000) bidirectional paths whose traversal time is in the range 1..70000 seconds (cows walk very slowly). Field 1 contains the barn. It takes no time to travel within a field (switch paths). Given the layout of Farmer John's farm and the location of each cow when the satellite flew over, determine set of cows who could be guilty. NOTE: Do not declare a variable named exactly 'time'. This will reference the system call and never give you the results you really want.
Input
* Line 1: Four space-separated integers: F, P, C, and M * Lines 2..P+1: Three space-separated integers describing a path: F1, F2, and T. The path connects F1 and F2 and requires T seconds to traverse. * Lines P+2..P+C+1: One integer per line, the location of a cow. The first line gives the field number of cow 1, the second of cow 2, etc.
第1行输入四个整数F,只C,和M;
接下来P行每行三个整数描述一条路,起点终点和通过时间.
Output
* Line 1: A single integer N, the number of cows that could be guilty of the crime.
* Lines 2..N+1: A single cow number on each line that is one of the cows that could be guilty of the crime. The list must be in ascending order.
Sample Input
1 4 2
1 2 1
2 3 6
3 5 5
5 4 6
1 7 9
1
4
5
3
7
Sample Output
1
2
3
4


#include<cstdio>
#include<algorithm>
using namespace std; struct na{
int y,z,ne;
na(){
ne=;
}
};
struct dui{
int v,n;
};
const int INF=;
int n,c,m,l[],r[],x,y,z,pp,num=,p[],nu,dis[],an=;
bool ans[];
na b[];
dui d[];
char cc;
int read(){
int a=;
cc=getchar();
while(cc<''||cc>'') cc=getchar();
while(cc>=''&&cc<='') a=a*+cc-,cc=getchar();
return a;
}
void in(int x,int y,int z){
num++;
if (l[x]==) l[x]=num;else b[r[x]].ne=num;
b[num].y=y;b[num].z=z;
r[x]=num;
}
void sw(int a,int b){
swap(p[d[a].n],p[d[b].n]);
swap(d[a],d[b]);
}
void utz(int x){
while(x>&&d[x].v<d[x>>].v) sw(x,x>>),x>>=;
}
void dtz(int j){
j=j*;
while(j<=nu){
if (j<nu&&d[j].v>d[j+].v) j++;
sw(j>>,j);
j*=;
}
sw(j>>,nu);
p[d[nu].n]=;
nu--;
}
int main(){
n=read();pp=read();m=read();c=read();
nu=n;
for (int i=;i<=pp;i++){
x=read();y=read();z=read();
in(x,y,z);in(y,x,z);
}
for (int i=;i<=n;i++) dis[i]=d[i].v=INF,d[i].n=i,p[i]=i;
d[].v=;
for (int i=;i<=n;i++){
x=d[].n;
if (d[].v>c) break;
dis[x]=d[].v;
dtz();
for (int j=l[x];j;j=b[j].ne)
if (p[b[j].y]&&d[p[b[j].y]].v>dis[x]+b[j].z&&dis[x]+b[j].z<=c){
d[p[b[j].y]].v=dis[x]+b[j].z;
utz(p[b[j].y]);
}
}
for (int i=;i<=m;i++){
x=read();
if (dis[x]<=c)an++,ans[i]=;
}
printf("%d\n",an);
for (int i=;i<=m;i++)
if (ans[i]) printf("%d\n",i);
}
bzoj:1681 [Usaco2005 Mar]Checking an Alibi 不在场的证明的更多相关文章
- 【BZOJ】1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=1681 太裸了.. #include <cstdio> #include <cstr ...
- bzoj1681[Usaco2005 Mar]Checking an Alibi 不在场的证明
Description A crime has been comitted: a load of grain has been taken from the barn by one of FJ's c ...
- BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯
题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec Memory Limit: 64 MB Description The c ...
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )
一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛
Description 约翰的牛们非常害怕淋雨,那会使他们瑟瑟发抖.他们打算安装一个下雨报警器,并且安排了一个撤退计划.他们需要计算最少的让所有牛进入雨棚的时间. 牛们在农场的F(1≤F≤200 ...
- BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机
Description 牛们干草要用完了!贝茜打算去勘查灾情. 有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一 ...
- BZOJ 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...
- bzoj 1680: [Usaco2005 Mar]Yogurt factory【贪心】
贪心,一边读入一边更新mn,用mn更新答案,mn每次加s #include<iostream> #include<cstdio> using namespace std; in ...
- bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】
二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...
随机推荐
- WindowsServer2012 搭建域错误“本地Administraor账户不需要密码”
标签:MSSQL/SQLServer/域控制器提升的先决条件验证失败/密码不符合要求 概述 在安装WindowsServer2012域控出现administrator账户密码不符合要求的错误,但是实际 ...
- 【Zookeeper】源码分析目录
Zookeeper源码分析目录如下 1. [Zookeeper]源码分析之序列化 2. [Zookeeper]源码分析之持久化(一)之FileTxnLog 3. [Zookeeper]源码分析之持久化 ...
- ES6常用语法
ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准.因为当前版本的ES6是在2015年发布的,所以又称ECMAScript 2015. 也就是说,ES6就是ES2015. ...
- 某次送温暖考试的 c题
题目大意: 给定n个点的无根树,树上每个点都有一个非负的点权. 树上的路径的价值定义为树上路径的点权和-树上路径的点权最大值; 现在给定一个参数P询问有多少条路径的价值是P的倍数(注意单点也算路径,路 ...
- bzoj 3143: [Hnoi2013]游走
Description 一个无向连通图,顶点从1编号到N,边从1编号到M. 小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 择当前顶点的某条边,沿着这条边走到下一个顶点, ...
- whereis 命令详解
whereis 作用:whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s).如果省略参数,则返回所有信息. 参数:-b 定位可 ...
- Lucene分词停用词库stopwords
! " $ % & ' ( ) * + , - -- . .. ... ...... ................... ./ .一 .数 .日 / // 0 1 2 3 4 5 ...
- Android开发之漫漫长途 IX——彻底掌握Binder
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- python爬取大众点评
拖了好久的代码 1.首先进入页面确定自己要抓取的数据(我们要抓取的是左侧分类栏-----包括美食.火锅)先爬取第一级分类(美食.婚纱摄影.电影),之后根据第一级链接爬取第二层(火锅).要注意第二级的p ...
- 基于MATLAB的中值滤波均值滤波以及高斯滤波的实现
基于MATLAB的中值滤波均值滤波以及高斯滤波的实现 作者:lee神 1. 背景知识 中值滤波法是一种非线性平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值. 中值滤 ...