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

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 389  Solved: 250
[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

BFS,答案要按顺序输出,有重边和自环

#include<stdio.h>
#include<vector>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;
typedef struct
{int y;int t;
}Line;
Line now;
queue<int> q;
vector<Line> G[505];
vector<int> C[505];
int bet[505], ans[105], vis[505];
int main(void)
{int n, m, p, x, y, t, T, i, cnt, j;scanf("%d%d%d%d", &n, &m, &p, &T);for(i=1;i<=m;i++){scanf("%d%d%d", &x, &y, &t);if(t>T)  continue;now.y = y, now.t = t;G[x].push_back(now);now.y = x;G[y].push_back(now);}memset(bet, 62, sizeof(bet));bet[1] = 0;for(i=1;i<=p;i++){scanf("%d", &x);C[x].push_back(i);}memset(vis, 0, sizeof(vis));q.push(1);vis[1] = 1;while(q.empty()==0){x = q.front();q.pop();vis[x] = 0;for(i=0;i<G[x].size();i++){y = G[x][i].y;t = G[x][i].t;if(bet[x]+t<bet[y] && bet[x]+t<=T){bet[y] = bet[x]+t;if(vis[y]==0){q.push(y);vis[y] = 1;}}}}cnt = 0;for(i=1;i<=n;i++){if(bet[i]<=T){for(j=0;j<C[i].size();j++)ans[++cnt] = C[i][j];}}sort(ans+1, ans+cnt+1);printf("%d\n", cnt);for(i=1;i<=cnt;i++)printf("%d\n", ans[i]);return 0;
}

bzoj 1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(BFS)相关推荐

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

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

  2. P6770 [USACO05MAR]Checking an Alibi 不在场的证明(spfa)

    不在场的证明 题目传送门 解题思路 这题就和香甜的黄油(SPFA)差不多,改个输入和输出就AC了 AC代码 #include<algorithm> #include<iostream ...

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

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

  4. bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机(最小生成树)

    1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 626  Solved: 436 ...

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

    1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 391  Solved: 258 ...

  6. BZOJ 1597: [Usaco2008 Mar]土地购买( dp + 斜率优化 )

    既然每块都要买, 那么一块土地被另一块包含就可以不考虑. 先按长排序, 去掉不考虑的土地, 剩下的土地长x递增, 宽y递减 dp(v) = min{ dp(p)+xv*yp+1 } 假设dp(v)由i ...

  7. [BZOJ] 1637: [Usaco2007 Mar]Balanced Lineup

    1637: [Usaco2007 Mar]Balanced Lineup Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 697  Solved: 463 ...

  8. bzoj 1598: [Usaco2008 Mar]牛跑步 [k短路 A*] [学习笔记]

    1598: [Usaco2008 Mar]牛跑步 题意:k短路 ~~貌似A*的题目除了x数码就是k短路~~ \[ f(x) = g(x) + h(x) \] \(g(x)\)为到达当前状态实际代价,\ ...

  9. [BZOJ] 1688: [Usaco2005 Open]Disease Manangement 疾病管理

    1688: [Usaco2005 Open]Disease Manangement 疾病管理 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 727  S ...

最新文章

  1. 面试:说说参数验证 @Validated 和 @Valid 的区别?
  2. 这本零差评且有趣的Python算法书有点火~
  3. PyTorch之实现LeNet-5卷积神经网络对mnist手写数字图片进行分类
  4. 在Windows 10中使用TortoiseGit进程gitlab仓库的管理
  5. wordpress rest api 漏洞又来了CVE-2017-5487 上次是修改文章内容这次可是泄露用户数据...
  6. autocad哪个版本最好用_分享家用游戏用Win10哪个版本最好最稳定(个人见解篇)...
  7. windows 2003 英文版支持中文显示、中文输入的设置方法
  8. 无人机技术在精细建模中的应用(PPT)
  9. acegis连接使用方法_arcgis工具使用方法
  10. h5打开小程序的方法 总结
  11. html闹钟设置,设置闹钟标签.html
  12. python求解一元二次方程
  13. vscode: Code Runner直接运行多文件C++程序
  14. 英语诗歌中的格律与韵 | Meter Rhyme
  15. mysql(day03)
  16. 数据结构与算法--哈夫曼树应用
  17. 7 125 kHz RFID技术
  18. 博实乐公布季度业绩,前三季度收入增长46.6%
  19. 给iOS App减肥
  20. Bert实战--文本分类(一)

热门文章

  1. python语言中文怎么读-python中文读什么
  2. 线上python课程一般多少钱-学习Python这门课程大概需要多久?费用是多少?
  3. python电脑配置-入门学python需要什么配置的电脑?
  4. 科大讯飞独家Founding赞助国际语音顶会,14篇论文被收录
  5. 贪吃蛇大战 java小游戏百度云源码
  6. Keil用C语言定义函数,STC单片机Keil中C语言函数定位的方法
  7. 漳州java,漳州学java,漳州学java学校,漳州学java效果怎么样
  8. flex布局实现垂直居中
  9. php 网关接口,[PHP] 通用网关接口CGI 的运行原理
  10. LIRe 源代码分析 2:基本接口(DocumentBuilder)