2218:thrall's Dream time limit: 1 Sec Memory Limit: MB
Submit: 253 Solved: 72
[Submit] [Status] [Web Board] Description
We never paid any heed to the ancient prophecies, like fools we clung to the old hatreds, and fought as we had for Generat Ions. 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 have 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 cont Rol. In a downpour night, Thrall falls to sleep in a ORC hall at Arathi Highlands, at this moment he heard a voice:
The sands of time has run out, son of Durotan. The cries of war echo upon the winds, the remnants of the past scar the land which are besieged once again by conflict. Heroes arise to challenge fate, and leads 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 leads your people to their destiny.
I'll answer all of your questions in time, young warchief. For-now, rally your warriors and prepare-to-leave, the cross the sea to the distant land of Kalimdor. We'll 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 could 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?
Input
There was multiple test case in the input file, first line was a case number T. Each test case would begin with a integers n (0 <= N < 2001) and M (0 <= M < 10001), where N is the number of Islands and M is number of portal. Next M lines Each line contains the integers a and B, indicated there is a portal on island a so people can go from a to b by this portal. The island numbered from 1 to N.
Output
For each test case, your output should are in one line with "Kalimdor is just ahead" (without quotes, hereinafter the same) If thrall and Grom can meet or "the Burning Shadow consume us all" otherwise as indicated in the sample output.
Sample Input
2
3 2
1 2
1 3
3 2
1 2
2 3
Sample Output
Case 1:the Burning Shadow consume us all
Case 2:kalimdor is just ahead
Hintsource
2013 ACM College Student Program Design contest in Shandong Province
Because the range of data in the topic is too large, you can select an indefinite length array to record, which saves time
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < stdlib.h> #include <queue> #include <vector> using namespace std; int n,m; BOOL v[2015],mm[2015][2015]; vector<int>map[2015]; void BFS (int x) {queue<int>q; while (!q.empty ()) {Q.pop (); } for (int j=0; j<map[x].size (); j + +) {Q.push (map[x][j]); V[MAP[X][J]] = true; } V[x] = true; while (!q.empty ()) {int t = Q.front (); Q.pop (); for (int j=0; j<map[t].size (); j + +) {if (v[map[t][j]] = = 0) {v[map[ T][J]] = true; Q.push (Map[t][j]); MM[X][MAP[T][J]] = true; }}}} int main () {int T; int KK = 0; scanf ("%d", &t); while (t--) {int x, y; scanf ("%d%d", &n,&m); for (int i=0, i<=n; i++) {for (int j=0; j<=n; J + +) {Mm[i][j] = False } Mm[i][i] = true; } for (int i=1; i<=n; i++) {map[i].clear (); } for (int i=0; i<m; i++) {scanf ("%d%d", &x,&y); Map[x].push_back (y); Mm[x][y] = true; } int flag = 0; for (int i=1; i<=n; i++) {memset (v,0,sizeof (v)); BFS (i); } for (int i=1;i<=n;i++) {for (int j=1;j<=n;j++) {if (mm I [j] = = 0 && mm[j][i] = = 0) {flag = 1; printf ("Case%d:the Burning Shadow consume US all\n", ++KK); Break }} if (flag = = 1) {break; }} if (flag = = 0) {printf ("Case%d:kalimdor is just ahead\n", ++KK); }} return 0; }
Fourth session of Shandong Province Thrall's Dream (Bfs+vector)