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.

    谷仓里发现谷物被盗!约翰正试图从C(1≤C≤100)只奶牛里找出那个偷谷物的罪犯.幸运的是,一个恰好路过的卫星拍下谷物被盗前M(1≤M≤70000)秒的农场的图片.这样约翰就能通过牛们的位置来判断谁有足够的时间来盗窃谷物.
    约翰农场有F(1≤F≤500)草地,标号1到F,还有P(1≤P≤1000)条双向路连接着它们.通过这些路需要的时间在1到70000秒的范围内.田地1上建有那个被盗的谷仓. 给出农场地图,以及卫星照片里每只牛所在的位置.请判断哪些牛有可能犯罪.
    

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行每行三个整数描述一条路,起点终点和通过时间.

接下来C行每行一个整数,表示一头牛所在的地点.

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.

    第1行输出嫌疑犯的数目,接下来一行输出一只嫌疑犯的编号.

Sample Input

7 6 5 8
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

4
1
2
3
4
 
 
 
 
反正数据特别水,什么最短路基本都能过,为了混0MS我就作死打了迪杰+堆优化,然而还WA了一发……
 
#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 不在场的证明的更多相关文章

  1. 【BZOJ】1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1681 太裸了.. #include <cstdio> #include <cstr ...

  2. 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 ...

  3. BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

    题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The c ...

  4. BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

    一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...

  5. BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛

    Description 约翰的牛们非常害怕淋雨,那会使他们瑟瑟发抖.他们打算安装一个下雨报警器,并且安排了一个撤退计划.他们需要计算最少的让所有牛进入雨棚的时间.    牛们在农场的F(1≤F≤200 ...

  6. BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机

    Description 牛们干草要用完了!贝茜打算去勘查灾情. 有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一 ...

  7. BZOJ 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...

  8. bzoj 1680: [Usaco2005 Mar]Yogurt factory【贪心】

    贪心,一边读入一边更新mn,用mn更新答案,mn每次加s #include<iostream> #include<cstdio> using namespace std; in ...

  9. bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】

    二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...

随机推荐

  1. 开源一个上架 App Store 的相机 App

    Osho 相机是我独立开发上架的一个相机 App,App Store地址:https://itunes.apple.com/cn/app/osho/id1203312279?mt=8.它支持1:1,4 ...

  2. visual studio 2012打开提示 未能将网站×××配置为使用 ASP.NET 4.5 和 尚未在Web服务器上注册,您需要手动将Web服务器配置为使用ASP.NET 4.5

    未能将网站×××配置为使用 ASP.NET 4.5.为了使此网站正确运行,您必须将它手动配置为使用ASP.NET 4.5. ASP.NET 4.5尚未在Web服务器上注册,您需要手动将Web服务器配置 ...

  3. C 函数参数 char **s与char *s[]

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/126 先来看一个小例子 : 编写函数遍历一个整型数组的元素,数组 ...

  4. Android 再按一次退出程序三种办法

    在Xamarin android中双击返回键退出程序的第一种做法 思路就是当用户按下返回键的时间超过两秒就退出,根据Keycode.Back判断用户按下的是返回键,重写这个OnKeyDown Date ...

  5. 如何录屏制作gif图片

    LICEcap简介: LICEcap是一款屏幕录制制作gif图片的工具,支持导出 GIF 动画图片格式,轻量级.使用简单,录制过程中可以随意改变录屏范围. LICEcap 直观易用,功能灵活,支持 W ...

  6. js scrollTop 事件

    代码: window.onscroll = function() { var t = document.documentElement.scrollTop || document.body.scrol ...

  7. Linux第三节

    三期第三讲1.ls --help:查看帮助(man 命令) :ls -l: 长格式形式: ls -i: 文件的inode节点: ls -t: 按修改时间排序: ls -a :显示隐藏文件: 2.文件管 ...

  8. python:发送消息给微信企业号

    # -*- coding:utf-8 -*- import requests import json ''' 基础环境:微信企业号 version:python 2.7 ''' class Send_ ...

  9. 日语编程语言"抚子" - 第三版特色初探

    原址: https://zhuanlan.zhihu.com/p/30800689 原文: 日语编程语言"抚子" - 第三版特色初探 它山之石可以攻玉. 学习其他的母语编程语言, ...

  10. DBCC page 数据页 堆 底层数据分布大小计算

    1.行的总大小: Row_Size = Fixed_Data_Size + Variable_Data_Size + Null_Bitmap + 4(4是指行标题开销) 开销定义: Fixed_Dat ...