【bzoj1689】[Usaco2005 Mar]Checking an Alibi 不在场的证明

1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明

Time Limit: 5 Sec   Memory Limit: 64 MB
Submit: 338   Solved: 220
[ Submit][ Status][ Discuss]

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 F
1 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 numb
er 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

HINT


Source

[ Submit][ Status][ Discuss]




最短路。。。

最后统计一下小等K的有几个点

这里我用SPFA来写


代码:

#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;

struct data
{
	int to,w;
};

const int maxn = 2000;
const int maxn_q = 2e5;
vector<data> edge[maxn];
int q[maxn_q],exist[maxn],dis[maxn],ans[maxn],n,m,k,c,tot;

void spfa()
{
	int h = 0,t = 1;
	for (int i = 1; i <= n; i++) dis[i] = 70001;
	dis[1] = 0;
	q[t] = 1;
	exist[1] = 1;
	while (h < t)
	{
		int u = q[++h];
		exist[u] = 0;
		for (int i = 0; i < edge[u].size(); i++)
		{
			data& e = edge[u][i];
			if (dis[u] + e.w < dis[e.to])
			{
				dis[e.to] = dis[u] + e.w;
				if (!exist[e.to])
				{
					exist[e.to] = 1;
					q[++t] = e.to;
				}
			}
		}
	}
}

int main()
{
	scanf("%d%d%d%d",&n,&m,&c,&k);
	for (int i = 1; i <= m; i++)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		edge[u].push_back((data){v,w});
		edge[v].push_back((data){u,w});
	}
	spfa();
	for (int i = 1; i <= c; i++)
	{
		int cow;
		scanf("%d",&cow);
		if (dis[cow] <= k)
			ans[++tot] = i;
	}
	printf("%d\n",tot);
	for (int i = 1; i <= tot; i++)
		printf("%d\n",ans[i]);
	return 0;
}


相关推荐
<p> 欢迎参加英特尔® OpenVINO™工具套件初级课程 !本课程面向零基础学员,将从AI的基本概念开始,介绍人工智能与视觉应用的相关知识,并且帮助您快速理解英特尔® OpenVINO™工具套件的基本概念以及应用场景。整个课程包含了视频的处理,深度学习的相关知识,人工智能应用的推理加速,以及英特尔® OpenVINO™工具套件的Demo演示。通过本课程的学习,将帮助您快速上手计算机视觉的基本知识和英特尔® OpenVINO™ 工具套件的相关概念。 </p> <p> 为保证您顺利收听课程参与测试获取证书,还请您于<strong>电脑端</strong>进行课程收听学习! </p> <p> 为了便于您更好的学习本次课程,推荐您免费<strong>下载英特尔® OpenVINO™工具套件</strong>,下载地址:https://t.csdnimg.cn/yOf5 </p> <p> 收听课程并完成章节测试,可获得本课程<strong>专属定制证书</strong>,还可参与<strong>福利抽奖</strong>,活动详情:https://bss.csdn.net/m/topic/intel_openvino </p> <p> 8月1日-9月30日,学习完成【初级课程】的小伙伴,可以<span style="color:#FF0000;"><strong>免费学习【中级课程】</strong></span>,中级课程免费学习优惠券将在学完初级课程后的7个工作日内发送至您的账户,您可以在:<a href="https://i.csdn.net/#/wallet/coupon">https://i.csdn.net/#/wallet/coupon</a>查询优惠券情况,请大家报名初级课程后尽快学习哦~ </p> <p> <span style="font-size:12px;">请注意:点击报名即表示您确认您已年满18周岁,并且同意CSDN基于商务需求收集并使用您的个人信息,用于注册OpenVINO™工具套件及其课程。CSDN和英特尔会为您定制最新的科学技术和行业信息,将通过邮件或者短信的形式推送给您,您也可以随时取消订阅不再从CSDN或Intel接收此类信息。 查看更多详细信息请点击CSDN“<a href="https://passport.csdn.net/service">用户服务协议</a>”,英特尔“<a href="https://www.intel.cn/content/www/cn/zh/privacy/intel-privacy-notice.html?_ga=2.83783126.1562103805.1560759984-1414337906.1552367839&elq_cid=1761146&erpm_id=7141654/privacy/us/en/">隐私声明</a>”和“<a href="https://www.intel.cn/content/www/cn/zh/legal/terms-of-use.html?_ga=2.84823001.1188745750.1560759986-1414337906.1552367839&elq_cid=1761146&erpm_id=7141654/privacy/us/en/">使用条款</a>”。</span> </p> <p> <br /> </p>
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页