bzoj 1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(BFS)
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.
Input
Output
Sample Input
Sample Output
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)相关推荐
- 【BZOJ】1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=1681 太裸了.. #include <cstdio> #include <cstr ...
- P6770 [USACO05MAR]Checking an Alibi 不在场的证明(spfa)
不在场的证明 题目传送门 解题思路 这题就和香甜的黄油(SPFA)差不多,改个输入和输出就AC了 AC代码 #include<algorithm> #include<iostream ...
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )
一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...
- 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 ...
- 1682: [Usaco2005 Mar]Out of Hay 干草危机
1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 391 Solved: 258 ...
- BZOJ 1597: [Usaco2008 Mar]土地购买( dp + 斜率优化 )
既然每块都要买, 那么一块土地被另一块包含就可以不考虑. 先按长排序, 去掉不考虑的土地, 剩下的土地长x递增, 宽y递减 dp(v) = min{ dp(p)+xv*yp+1 } 假设dp(v)由i ...
- [BZOJ] 1637: [Usaco2007 Mar]Balanced Lineup
1637: [Usaco2007 Mar]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MB Submit: 697 Solved: 463 ...
- bzoj 1598: [Usaco2008 Mar]牛跑步 [k短路 A*] [学习笔记]
1598: [Usaco2008 Mar]牛跑步 题意:k短路 ~~貌似A*的题目除了x数码就是k短路~~ \[ f(x) = g(x) + h(x) \] \(g(x)\)为到达当前状态实际代价,\ ...
- [BZOJ] 1688: [Usaco2005 Open]Disease Manangement 疾病管理
1688: [Usaco2005 Open]Disease Manangement 疾病管理 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 727 S ...
最新文章
- 面试:说说参数验证 @Validated 和 @Valid 的区别?
- 这本零差评且有趣的Python算法书有点火~
- PyTorch之实现LeNet-5卷积神经网络对mnist手写数字图片进行分类
- 在Windows 10中使用TortoiseGit进程gitlab仓库的管理
- wordpress rest api 漏洞又来了CVE-2017-5487 上次是修改文章内容这次可是泄露用户数据...
- autocad哪个版本最好用_分享家用游戏用Win10哪个版本最好最稳定(个人见解篇)...
- windows 2003 英文版支持中文显示、中文输入的设置方法
- 无人机技术在精细建模中的应用(PPT)
- acegis连接使用方法_arcgis工具使用方法
- h5打开小程序的方法 总结
- html闹钟设置,设置闹钟标签.html
- python求解一元二次方程
- vscode: Code Runner直接运行多文件C++程序
- 英语诗歌中的格律与韵 | Meter Rhyme
- mysql(day03)
- 数据结构与算法--哈夫曼树应用
- 7 125 kHz RFID技术
- 博实乐公布季度业绩,前三季度收入增长46.6%
- 给iOS App减肥
- Bert实战--文本分类(一)
热门文章
- python语言中文怎么读-python中文读什么
- 线上python课程一般多少钱-学习Python这门课程大概需要多久?费用是多少?
- python电脑配置-入门学python需要什么配置的电脑?
- 科大讯飞独家Founding赞助国际语音顶会,14篇论文被收录
- 贪吃蛇大战 java小游戏百度云源码
- Keil用C语言定义函数,STC单片机Keil中C语言函数定位的方法
- 漳州java,漳州学java,漳州学java学校,漳州学java效果怎么样
- flex布局实现垂直居中
- php 网关接口,[PHP] 通用网关接口CGI 的运行原理
- LIRe 源代码分析 2:基本接口(DocumentBuilder)