第四届 山东省ACM B Thrall’s Dream(连通图 OR BFS)
2017-04-13 10:15
260 查看
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 Chaoshas 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?
输入
There are multiple test case in the input file, first line is a case number T. Each test case will begin with two integers N (0 <= N < 2001) and M (0 <= M < 10001), where Nis the number of islands and M is number of portal. Next M lines each line contains two integers a and b, indicated there is a portal in island a that people can go from a to b by this portal. The island numbered from 1 to N.
输出
For each test case, your output should be in one line with “Kalimdor is just ahead” (without quotes, hereinafter the same) if Thrall and Grom can meet or “The Burning Shadowconsume us all” otherwise as indicated in the sample output.
示例输入
23 21 21 33 21 22 3
示例输出
Case 1: The Burning Shadow consume us allCase 2: Kalimdor is just ahead
题意为给定n个点和m条有向边,问能不能任意给出两个点,至少有一条路径可以从a到b。
has[i][j],表示可以从i到达j, 对于每个点s,进行广搜,记录下has[s][ ] .
然后只要判断一下对于任意两个点都满足 has[i][j]==1||has[j][i]==1,就可以了。
#include <iostream> #include <stdio.h> #include <algorithm> #include <string.h> #include <stdlib.h> #include <cmath> #include <iomanip> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <cctype> #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z) using namespace std; const int maxn=2010; vector<int>g[maxn]; bool has[maxn][maxn]; bool vis[maxn]; int n,m; bool ok; void bfs(int s) { memset(vis,0,sizeof(vis)); vis[s]=1; queue<int>q; q.push(s); while(!q.empty()) { int first=q.front(); // cout<<"fist"<<first<<endl; q.pop(); int len=g[first].size(); for(int i=0;i<len;i++) { int v=g[first][i]; if(vis[v]) continue; has[s][v]=1; q.push(v); vis[v]=1; } } } int main() { int t,c=1; rd(t); while(t--) { ok=1; rd2(n,m); memset(has,0,sizeof(has)); for(int i=0;i<maxn;i++) g[i].clear(); int u,v; while(m--) { rd2(u,v); g[u].push_back(v); } for(int i=1;i<=n;i++) { bfs(i); }/* for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) cout<<has[i][j]<<" "; cout<<endl; }*/ 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",c++); else printf("Case %d: The Burning Shadow consume us all\n",c++); } return 0; }
参考网址:http://blog.csdn.net/sr_19930829/article/details/44925325
相关文章推荐
- 山东省第四届ACM大学生程序设计竞赛 Thrall’s Dream(单源强连通分量)
- Thrall’s Dream(山东省第四届ACM大学生程序设计竞赛 )
- 2013年山东省第四届ACM大学生程序设计竞赛 Problem I Thrall’s Dream 图,2n遍dfs
- SDUT 2604 Thrall’s Dream (bfs||单连通)
- 第四届 山东省ACM A^X mod P (分解优化=哈希+打表)
- sdut2605 A^X mod P 山东省第四届ACM省赛(打表,快速幂模思想,哈希)
- 山东省第四届ACM省赛 A SDUT 2603 Rescue The Princess(简单数学题)
- SDUT 2604 Thrall’s Dream (单连通的判断)
- 第四届 山东省ACM Rubik’s cube(爆搜)
- 第四届 山东省ACM Boring Counting(划分树+二分 主席树待整理)
- Contest Print Server (2013年山东省第四届ACM大学生程序设计竞赛):
- Mountain Subsequences(山东省第四届ACM大学生程序设计竞赛)
- 2013山东省第四届ACM省赛 Rescue The Princess
- 山东省第四届ACM大学生程序设计竞赛-Alice and Bob(二进制&&找规律)
- 山东省第三届ACM省赛题——Thrall’s Dream(DFS)
- 山东省第四届ACM大学生程序设计竞赛解题报告(部分)
- 山东省第一届ACM省赛 B SDUT 2152 Balloons(简单的BFS)
- sdut 2604 Thrall’s Dream 判断一个图是否单侧连通
- 2013山东省第四届ACM省赛 Contest Print Server
- 山东省第四届ACM-H Boring Counting