码迷,mamicode.com
首页 > 其他好文 > 详细

第四届山东省赛 Thrall’s Dream(BFS+vector)

时间:2015-04-07 21:44:04      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

2218: Thrall’s Dream

Time Limit: 1 Sec  Memory Limit: 128 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 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?

Input

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 N is 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.

Output

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 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

HINT

Source

2013年山东省第四届ACM大学生程序设计竞赛



因为题目中的数据范围太大,可以选择不定长数组进行记录,这样省时间



#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;  
}  















第四届山东省赛 Thrall’s Dream(BFS+vector)

标签:

原文地址:http://blog.csdn.net/yeguxin/article/details/44925241

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!