山东省第四届ACM大学生程序设计竞赛 Thrall’s Dream(单源强连通分量)
来源:互联网 发布:阿里大数据平台建成 编辑:程序博客网 时间:2024/05/21 11:10
Thrall’s Dream
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
We never paid any heed to the ancient prophecies, like fools we clung to the old hatreds, and fought as we had for generations. Until one day the sky rained fire, and a new enemy came upon us. We stand now upon the brink of destruction, for the Reign of Chaos has come at last.
Thrall, the warchief of the Orcish Horde, all along, he led his tribe live in the fringe of Lordaeron under the human control. In a downpour night, Thrall falls into sleep in a Orc hall at Arathi Highlands, at this moment he heard a voice:
“The sands of time have run out, son of Durotan. The cries of war echo upon the winds, the remnants of the past scar the land which is besieged once again by conflict. Heroes arise to challenge fate, and lead their brethren to battle. As mortal armies rush blindly towards their doom, The Burning Shadow comes to consume us all. You must rally the Horde, and lead your people to their destiny.
I will answer all of your questions in time, young warchief. For now, rally your warriors and prepare to leave this land, cross the sea to the distant land of Kalimdor. We will speak again. ”
Thrall believes the prophesy of Blood Raven Medivh. Three days later, He and Grom Hellscream's Warsong Clan meet in the Lordaeron coast to the distant lands of Kalimdor. But the Goblin Zeppelins they take encountered storms in the middle. Thrall and Grom falling to the islands, they want to find each other and then to Kalimdor.
For the sake of simplicity, we assume that Thrall and Grom may fall into any islands x and y, only by Thrall to find Grom or by Grom to find Thrall. Give you the map of this island, please judge that Thrall and Gtom can meet?
输入
输出
示例输入
23 21 21 33 21 22 3
示例输出
Case 1: The Burning Shadow consume us allCase 2: Kalimdor is just ahead
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>using namespace std;const int maxn=10005;vector <int>g[maxn];bool has[maxn][maxn];bool vis[maxn];void bfs(int s){ memset(vis,0,sizeof(vis)); vis[s]=1; queue<int>q; q.push(s); while(!q.empty()) { int p; p=q.front(); q.pop(); int len=g[p].size(); for(int i=0;i<len;i++) { int t; t=g[p][i]; if(vis[t])continue; has[s][t]=1; vis[t]=1; q.push(t); } }}int main(){ int t,cnt=1; scanf("%d",&t); while(t--) { int ok=1; int n,m; scanf("%d%d",&n,&m); memset(has,0,sizeof(has)); for(int i=1;i<=n;i++)g[i].clear(); for(int i=1;i<=m;i++) { int a,b; scanf("%d%d",&a,&b); g[a].push_back(b); } for(int i=1;i<=n;i++) bfs(i); for(int i=1;i<n;i++) {for(int j=i+1;j<=n;j++) { if(!has[i][j]&&!has[j][i]) { ok=0;break;} } if(ok==0)break; } if(ok) printf("Case %d: Kalimdor is just ahead\n",cnt++); else printf("Case %d: The Burning Shadow consume us all\n",cnt++); } return 0;}/***************************************************User name: 但求心安Result: AcceptedTake time: 700msTake Memory: 2304KBSubmit time: 2017-05-05 17:02:41****************************************************/
- 山东省第四届ACM大学生程序设计竞赛 Thrall’s Dream(单源强连通分量)
- Thrall’s Dream(山东省第四届ACM大学生程序设计竞赛 )
- 2013年山东省第四届ACM大学生程序设计竞赛 Problem I Thrall’s Dream 图,2n遍dfs
- 第四届 山东省ACM B Thrall’s Dream(连通图 OR BFS)
- 第四届山东省赛 Thrall’s Dream(BFS+vector)
- 第四届 山东省ACM大学生程序设计竞赛
- Mountain Subsequences(山东省第四届ACM大学生程序设计竞赛)
- 2013年山东省第四届ACM大学生程序设计竞赛
- 山东省第四届ACM大学生程序设计竞赛 Rescue The Princess
- 山东省第四届ACM大学生程序设计竞赛 Mountain Subsequences dp
- 山东省第四届ACM大学生程序设计竞赛Mountain Subsequences
- 山东省第四届ACM大学生程序设计竞赛 Alice and Bob
- 山东省第四届ACM大学生程序设计竞赛 Rescue The Princess
- 山东省第三届ACM省赛题——Thrall’s Dream(DFS)
- 2013年山东省第四届ACM大学生程序设计竞赛-Alice and Bob (找规律+二进制)
- 山东省第四届ACM大学生程序设计竞赛-Rescue The Princess(计算几何)
- 山东省第四届ACM大学生程序设计竞赛-Contest Print Server(模拟)
- 山东省第四届ACM大学生程序设计竞赛-Alice and Bob(二进制&&找规律)
- chm文件打不开解决方法
- jQuery的基本选择器
- JDK之Byte源码解析
- 《Android攻防实战》读书笔记——保护App安全
- 如何将tomcat webapp目录下的项目 路径改为 / (原访问路径需要加项目名)
- 山东省第四届ACM大学生程序设计竞赛 Thrall’s Dream(单源强连通分量)
- 《Android攻防实战》度数笔记——Android安全评估工具——Drozer (日后学习)
- 缓存技术概述
- 5.5
- ssm整合
- webstorm配置编译sass的输出目录
- js返回上一页并刷新的几种方法
- Python 3基础教程1-环境安装和运行环境
- Canvas绘图的使用(一)