bzoj 1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(BFS)
来源:互联网 发布:windows菜单栏打不开 编辑:程序博客网 时间:2024/05/17 05:15
1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 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)
- bzoj1681[Usaco2005 Mar]Checking an Alibi 不在场的证明
- 【bzoj1689】[Usaco2005 Mar]Checking an Alibi 不在场的证明
- poj 2394 Checking an Alibi--(Dijkstra)
- 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】
- POJ 2394 Checking an Alibi(最短路)
- Checking an Alibi(最短路径 Dijkstra)
- POJ2394 Checking an Alibi 最短路
- POJ2394,Checking an Alibi,Dijkstra单源最短路
- POJ 2394 Checking an Alibi【SPFA】
- bzoj [Usaco2005 mar]Ombrophobic Bovines 发抖的牛 最大流
- poj 2393 && bzoj 1680: [Usaco2005 Mar]Yogurt factory(贪心)
- Ubuntu 下实现FTP服务器,SSH服务器,邮件服务器,Web服务器(一)
- 1006. Sign In and Sign Out (25)
- 程序33
- rem布局在webview中页面错乱
- Synchronized与Lock锁的区别
- bzoj 1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(BFS)
- Spring 框架简介
- H5中关于自定义属性的设置和获取
- Java入门之编程基础(二)
- 程序34
- 【Python+Tensorflow】Deep Q Network (DQN) 迷宫示例代码整理
- 程序35
- WinForm DataGridView 可编辑单元格拷贝
- HDU