[ACM] SDUT 2604 Thrall’s Dream

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?

输入

    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.

输出

    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. 

示例输入

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


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值