Problem B: Thrall's Dream
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 17 Solved: 3
[Submit][Status][Web Board]
Description
Problem 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
题意:
有 T 个 case,每个 case 都给出 N(0 ~ 2001),M(0 ~ 10001)代表有 N 个节点 M 条单向边。问是否任意两点间 a 和 b ,要么存在 a 到达 b,要么存在 b 到达 a。如果满足条件则输出 Kalimdor is just ahead,不能则输出 The Burning Shadow consume us all。
思路:
强连通分量 + 拓扑排序。要么 a 能到达 b,要么 b 能达 a,即存在一条直路从起点到终点,这条直路是没有分岔的,如果有分岔的话就不能满足题意了。除此之外,这个图还可能有环,有环则可以用强连通分量缩点表示成一个点,这个点可以存在在拓扑序列中。强连通分量缩点后,再对强连通分量建图,最后判断是否存在唯一确定的拓扑序即可。
AC:
#include <cstdio> #include <cstring> #include <algorithm> #include <stack> using namespace std; const int NMAX = 2005; const int EMAX = 10005; int n, m, ind; int v[EMAX], fir[NMAX], Next[EMAX]; int scc_cnt, dfs_clock; int pre[NMAX], low[NMAX], cmp[NMAX]; int deg[NMAX], nscc[NMAX][NMAX]; stack<int> s; void add_edge(int f, int t) { v[ind] = t; ++deg[t]; Next[ind] = fir[f]; fir[f] = ind; ++ind; } void dfs(int u) { low[u] = pre[u] = ++dfs_clock; s.push(u); for (int e = fir[u]; e != -1; e = Next[e]) { if (!pre[ v[e] ]) { dfs ( v[e] ); low[u] = min(low[u], low[ v[e] ]); } else if (!cmp[ v[e] ]) { low[u] = min(low[u], pre[ v[e] ]); } } if (low[u] == pre[u]) { ++scc_cnt; for (;;) { int x = s.top(); s.pop(); cmp[x] = scc_cnt; if (x == u) break; } } } void scc() { dfs_clock = scc_cnt = 0; memset(low, 0, sizeof(low)); memset(pre, 0, sizeof(pre)); memset(cmp, 0, sizeof(cmp)); for (int u = 1; u <= n; ++u) { if (!pre[u]) dfs(u); } } void make_scc() { memset(deg, 0, sizeof(deg)); memset(nscc, 0, sizeof(nscc)); for (int u = 1; u <= n; ++u) { int f = u; for (int e = fir[u]; e != -1; e = Next[e]) { int t = v[e]; if (cmp[f] != cmp[t] && !nscc[ cmp[f] ][ cmp[t] ]) { nscc[ cmp[f] ][ cmp[t] ] = 1; ++deg[ cmp[t] ]; } } } } bool topo() { for (int i = 1; i <= scc_cnt; ++i) { int ans = 0; for (int j = 1; j <= scc_cnt; ++j) { if (!deg[j]) { ++ans; deg[j] = 1; for (int t = 1; t <= scc_cnt; ++t) { if (nscc[j][t]) --deg[t]; } } } if (ans > 1) return false; } return true; } int main() { int t; scanf("%d", &t); for (int tt = 1; tt <= t; ++tt) { ind = 0; memset(fir, -1, sizeof(fir)); scanf("%d%d", &n, &m); while (m--) { int f, t; scanf("%d%d", &f, &t); add_edge(f, t); } scc(); make_scc(); printf("Case %d: ", tt); if( topo() ) printf("Kalimdor is just ahead\n"); else printf("The Burning Shadow consume us all\n"); } return 0; }
相关推荐
2024-2030全球及中国PCB接触式探头行业研究及十五五规划分析报告
网站界面设计mortal0418代码
PHP毕业设计-校园失物招领系统源码+数据库.zip个人经导师指导并认可通过的高分毕业设计项目,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者。也可作为课程设计、期末大作业。包含全部项目源码、该项目可以直接作为毕设使用。项目都经过严格调试,确保可以运行! PHP毕业设计-校园失物招领系统源码+数据库.zip个人经导师指导并认可通过的高分毕业设计项目,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者。也可作为课程设计、期末大作业。包含全部项目源码、该项目可以直接作为毕设使用。项目都经过严格调试,确保可以运行! PHP毕业设计-校园失物招领系统源码+数据库.zip个人经导师指导并认可通过的高分毕业设计项目,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者。也可作为课程设计、期末大作业。包含全部项目源码、该项目可以直接作为毕设使用。项目都经过严格调试,确保可以运行! PHP毕业设计-校园失物招领系统源码+数据库.zip个人经导师指导并认可通过的高分毕业设计项目,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者。也可
2024年神经酸行业分析报告.pptx
【Java爬虫】信息抓取的实现 完整实例(源码)
rain-drop.PNG
FEDformer.pdf
基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资源交流系统:毕业源码案例设计.rar基于ASP.NET三层模式的网上学习资
完整代码!扫雷游戏,vs2010使用vs2010开发小游戏,这是一个扫雷的游戏,适应于大作业和毕业论文.zip
JDK 8 0 apidoc 带完整索引和目录
可以进行模拟银行服务,有多种功能。
校园共享单车管理系统 软件工程做的课程设计,里面是JSP源码,后台连接数据库,可直接调试运行成功。
去水印版,aspose.words-19.7-jdk17.jar、aspose-words-19.7.pom
NKUcs22级机器学习实验全套代码于此,希望造福学弟学妹。
springboot校园医疗保险管理系统
QPSK的锁相环程序,在MATLAB环境下编写的,用来进行QPSK通信系统的仿真和实际信号载波同步的提取
stm32项目知识领域: 网络安全 技术关键词: 漏洞分析、渗透测试、加密算法 内容关键词: 攻击防范、身份验证、网络流量分析 用途: 学习保护信息系统免受恶意攻击和数据泄露 资源描述: "OWASP官方网站"提供了全面的网络安全知识和工具,包括常见漏洞、安全指南和最佳实践。
springboot时间管理系统 系统实现了首页,个人中心,系统公告管理,用户管理,时间分类管理,事件数据管理,目标数据管理,用户日记管理等功能。 项目关键技术 开发工具:IDEA 、Eclipse 编程语言: Java 数据库: MySQL5.7+ 框架:ssm、Springboot 前端:Vue、ElementUI 关键技术:springboot、SSM、vue、MYSQL、MAVEN 数据库工具:Navicat、SQLyog
SNR,SNDR,THD,ENOB,SFDR的matlab计算程序 matla
springboot商品推荐系统 项目关键技术 开发工具:IDEA 、Eclipse 编程语言: Java 数据库: MySQL5.7+ 框架:ssm、Springboot 前端:Vue、ElementUI 关键技术:springboot、SSM、vue、MYSQL、MAVEN 数据库工具:Navicat、SQLyog