题意:求从1到N是否存在一条路,可以遍历每个节点。
思路:求任意两点之间是否通畅即可;
疑惑:完全暴力,bfs但是TLE,问题在于求连通分量(PS:不会)贴别人代码,先保存着。
#include <bits/stdc++.h>
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define M 10007
#define N 2007
using namespace std;
const int inf = 0x7f7f7f7f;
const int mod = ;
struct node
{
int v;
int next;
} g[M];
int head[N],ct;
bool ok[N][N];
bool vt[N];
int n,m; void add(int u,int v)
{
g[ct].v = v;
g[ct].next = head[u];
head[u] = ct++;
}
void bfs(int s)
{
int i;
for (i = ; i <= n; ++i) vt[i] = false;
vt[s] = true;
queue<int> Q;
Q.push(s);
while (!Q.empty())
{
int u = Q.front();
Q.pop();
for (i = head[u]; i != -; i = g[i].next)
{
int v = g[i].v;
if (!vt[v])
{
vt[v] = true;
ok[s][v] = true;
Q.push(v);
}
}
}
}
int main()
{
// Read();
int T;
int i,j;
scanf("%d",&T);
int cas = ;
while (T--)
{
scanf("%d%d",&n,&m);
CL(head,-);
ct = ;
int x,y;
for (i = ; i < m; ++i)
{
scanf("%d%d",&x,&y);
add(x,y);
}
CL(ok,false);
for (i = ; i <= n; ++i) ok[i][i] = true;
for (i = ; i <= n; ++i) bfs(i);
bool flag = false;
for (i = ; i <= n && !flag; ++i)
{
for (j = ; j <= n && !flag; ++j)
{
if (ok[i][j] || ok[j][i]) continue;
else
{
flag = true;
break;
}
}
}
if (!flag) printf("Case %d: Kalimdor is just ahead\n",cas++);
else printf("Case %d: The Burning Shadow consume us all\n",cas++);
}
return ;
}