Light OJ 1111 Best Picnic Ever
来源:互联网 发布:淘宝联盟店铺活动推广 编辑:程序博客网 时间:2024/06/05 08:44
注意理解题目的意思:是求所有人都能到的点的个数,直接以每个人为起点bfs就行了。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<vector>#define sf scanf#define pf printfusing namespace std;bool vis[1005];int able[1005];int q[1005];vector<int> G[1005];void unit(){ memset(G,0,sizeof(G)); memset(able,0,sizeof(able)); for(int i=1;i<=1000;i++) G[i].clear();}void bfs(int st){ queue<int> Q; memset(vis,0,sizeof(vis)); vis[st]=1,able[st]++; Q.push(st); while(!Q.empty()) { int now=Q.front(); Q.pop(); for(int i=0;i<G[now].size();i++) { int tmp=G[now][i]; if(!vis[tmp]) able[tmp]++,vis[tmp]=1,Q.push(tmp); } }}int main(){ int i,u,v,T,ca=0; sf("%d",&T); while(T--) { int k,n,m,_max=-1; sf("%d%d%d",&k,&n,&m); for(i=1;i<=k;i++) sf("%d",&q[i]); unit(); while(m--) { sf("%d%d",&u,&v); G[u].push_back(v); _max=max(_max,max(u,v)); } for(i=1;i<=k;i++) bfs(q[i]); int ans=0; for(i=1;i<=_max;i++) if(able[i]==k) ans++; pf("Case %d: %d\n",++ca,ans); } return 0;}
0 0
- Light OJ 1111 Best Picnic Ever
- LightOj 1111 - Best Picnic Ever
- LightOJ - 1111 Best Picnic Ever
- LightOJ - 1111 Best Picnic Ever (搜索)
- LightOJ 1111 Best Picnic Ever 简单bfs
- Light OJ 1304 The Best Contest Site Ever 行列匹配变形
- Lightoj1111——Best Picnic Ever(dfs)
- Best Training Ever
- light oj
- light oj
- Light OJ
- Light OJ
- UVa 11556 - Best Compression Ever
- The 46 Best-ever Freeware Utilities
- The 46 Best-ever Freeware Utilities-some
- Oracle Buys Sun: The Best Deal Ever
- toj3095 Best Compression Ever 不懂 求解释?
- Top 20 Best Agile Development Books, Ever
- 七月工作笔记 7.7 - 7.11
- fork1
- 悲观锁和乐观锁学习笔记-非原创,资料整理
- 多线程之10——SynchronousQueue(同步队列)
- vsftp 登录报错:500 OOPS: cannot change directory:/home/*******
- Light OJ 1111 Best Picnic Ever
- centos下hadoop的安装
- 黑马程序员_IO_字符流
- 交大OJ 1760 Higher Mathematics
- 【PLSQL】 定义record记录
- linux-gcc 编译时头文件和库文件搜索路径
- 嵌入式Linux操作系统的版本查询
- JS判断用户浏览设备是移动设备还是PC机
- CListCtrl控件的标题栏添加checkbox