【bzoj1689】[Usaco2005 Mar]Checking an Alibi 不在场的证明
来源:互联网 发布:成人高考网络教育 编辑:程序博客网 时间:2024/06/07 02:38
1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 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.
Input
Output
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
HINT
Source
Silver
最短路。。。
最后统计一下小等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;}
- 【bzoj1689】[Usaco2005 Mar]Checking an Alibi 不在场的证明
- bzoj1681[Usaco2005 Mar]Checking an Alibi 不在场的证明
- bzoj 1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(BFS)
- pku2394 Checking an Alibi
- Checking an Alibi
- POJ Checking an Alibi
- PKU 2394---Checking an Alibi
- poj 2394 Checking an Alibi
- poj 2394 Checking an Alibi
- POJ2394 Checking an Alibi【Dijkstra】
- POJ2394 Checking an Alibi 最短路
- POJ2394,Checking an Alibi,Dijkstra单源最短路
- POJ 2394 Checking an Alibi【SPFA】
- poj 2394 Checking an Alibi--(Dijkstra)
- PKU 2394 ( Checking an Alibi )(Dijkstra 最短路径)
- POJ2394 Checking an Alibi ——最短路
- POJ 2394 Checking an Alibi(最短路)
- POJ 2394 Checking an Alibi 简单最短路
- 第十届河南省程序设计竞赛总结 !
- Git(5)——查看修改内容
- 基于Docker Swarm的Docker Service常见命令
- VScode使用--代码段设置console.log以及调整代码段提示的显示位置
- B. T-Shirt Hunt
- 【bzoj1689】[Usaco2005 Mar]Checking an Alibi 不在场的证明
- 常见的adb指令
- 浅谈java socket通信,并附源码
- 关于排序算法的思想及实现
- 浅谈视频会议系统的运行与维护
- CentOS 7.x修改网卡名称
- Linux运维笔记-文档总结-DNS的介绍及各种DNS模式的部署(全)
- 又是一次面试~
- hdu1465 不容易系列之一 裸错排