UPC2218: Thrall’s Dream

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

23 21 21 33 21 22 3

Sample Output

Case 1: The Burning Shadow consume us allCase 2: Kalimdor is just ahead

HINT

Source

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


#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstdlib>
#include<cstring>
/**********
<cstring>是清空数组用的,开始因为没有加清空WA了好多次
**********/
using namespace std;//这个一定要写在最前面
const int maxn = 2005;
vector<short> g[maxn];//用来存储输入的有向边
bool can[maxn][maxn];//用一个bool的二维数组来判断是否连通

int N,M;


bool ok()//最后用来判断的数组,已经把有向边连通的边存到了里面
{
    for(int i=1;i<=N;i++)
    {
        for(int j=i+1;j<=N;j++)
            if(!can[i][j] && !can[j][i])//如果i和j  还有j和i都不能连通的话,就反回false
            return false;
    }
    return true;
}


void bfs(int x)///bfs
///
{
    queue<short> que;
    ///队列,用来存放先入的一个节点(这个节点就是x),以及这个节点连通的点
    ///如果有比这个节点大的连通,也就是与x连通的节点比x大,那么也会存放到队列里,在去找连通点
    que.push(x);//出队
    while(!que.empty())
    {
        short q = que.front();
        que.pop();///每次的q就是当前活跃的节点,寻找与当前q连通的点
        if(q<x)///如果这个当前活跃的q比最初的x小的话呢
            ///这里小的话说明之前已经把这个第q行已经便利完了,避免了重复
        {
            for(int i=1;i<=N;i++)
                if(can[q][i])///把q的哪一行,也就是在can数组里的哪一行便利一遍,如果有与q连通的
                can[x][i]=true;///就说明该点i也与x连通
        ///因为x与q连通,q与i连通,所以x与i也连通
        }
        else
        {///当然,q不比x小的话呢,就要从新找q那个不定长数组里存储的有向边来判定是否连通
            for(int i=0;i<g[q].size();i++)///把g[q]的便利一遍

            {
                int y = g[q][i];///每个便利出来的点
                if(!can[x][y])///判断每个便利出来的点y是否已经判断过了

                {
                    can[x][y]=true;///.如果y是个新的点,把他与x的连通性变成 真
                    
                    que.push(y);///并把y加入到要判断的队列中,
                    ///此时的状态是x与q连通,(也有可能q就是x本身,那么就不用判),q与y连通,再去看y与谁连通
                }
            }
        }
    }
}
int main()
{
    int T,Kase=1;
    cin>>T;
    while(T--)
    {
        cin>>N>>M;
        for(int i=1;i<=N;i++) g[i].clear();
       
        while(M--)
        {
            int a,b;
            cin>>a>>b;
            g[a].push_back(b);
        }
         memset(can,0,sizeof(can));
        for(int i=1;i<=N;i++)
            bfs(i);
        cout<<"Case "<<Kase++<<": ";
        if(ok())
            cout<<"Kalimdor is just ahead\n";
        else
            cout<<"The Burning Shadow consume us all\n";
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值