HDU 1269 迷宫城堡

pid=1269" target="_blank" style="">题目链接

题意:中文题

思路:强连通模板题

代码:

#include <cstdio>
#include <cstring>
#include <vector>
#include <stack>
using namespace std; const int N = 10005; int n, m;
vector<int> g[N], scc[N];
int pre[N], lowlink[N], sccno[N], dfs_clock, scc_cnt;
stack<int> S; void dfs_scc(int u) {
pre[u] = lowlink[u] = ++dfs_clock;
S.push(u);
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (!pre[v]) {
dfs_scc(v);
lowlink[u] = min(lowlink[u], lowlink[v]);
} else if (!sccno[v])
lowlink[u] = min(lowlink[u], pre[v]);
}
if (lowlink[u] == pre[u]) {
scc_cnt++;
int x = S.top();
while (x != u) {
sccno[x] = scc_cnt;
S.pop();
x = S.top();
}
}
} void find_scc(int n) {
dfs_clock = scc_cnt = 0;
memset(sccno, 0, sizeof(sccno));
memset(pre, 0, sizeof(pre));
for (int i = 1; i <= n; i++)
if (!pre[i]) dfs_scc(i);
} int main() {
while (~scanf("%d%d", &n, &m) && n || m) {
int u, v;
for (int i = 1; i <= n; i++) g[i].clear();
while (m--) {
scanf("%d%d", &u, &v);
g[u].push_back(v);
}
find_scc(n);
if (scc_cnt <= 1) printf("Yes\n");
else printf("No\n");
}
return 0;
}

HDU 1269 迷宫城堡(强连通)的更多相关文章

  1. hdu 1269 迷宫城堡 强连通分量

    迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. hdu - 1269 迷宫城堡 (强连通裸题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1269 判断一个图是不是强连通,缩点之后判断顶点数是不是为1即可. #include <iostream&g ...

  3. hdu 1269 迷宫城堡

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1269 迷宫城堡 Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个 ...

  4. HDU 1269 迷宫城堡(判断有向图强连通分量的个数,tarjan算法)

    迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. hdu 1269 迷宫城堡(Targin算法)

    ---恢复内容开始--- 迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. HDU 1269 迷宫城堡 (Kosaraju)

    题目链接:HDU 1269 Problem Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000), ...

  7. hdu 1269 迷宫城堡 最简单的联通图题 kosaraju缩点算法

    迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Des ...

  8. HDU 1269 迷宫城堡(向量)(Tarjan模版题)

    迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. HDU 1269.迷宫城堡-Tarjan or 双向DFS

    迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

随机推荐

  1. atlas z 轴

    问题源自一个帖子,因为上传的图比较多,就另开了这个贴写下自己的试验结果,原帖在下面链接中 http://game.ceeger.com/forum/read.php?tid=8911#info NGU ...

  2. Win8.1应用开发之异步编程

    在win8应用商店开发时,我们会遇到很多异步方法.它们存在的目的就是为了确保你的应用在运行须要大量时间的任务时仍能保持良好的响应,也就是说调用异步API是为了响应用户的操作.设想一下我们点击一个But ...

  3. hdu1248

    Problem Description 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前. 死亡 ...

  4. libvirt学习

    高级libvirt API可划分为5个API部分:虚拟机监控程序连接API.域API.网络API.存储卷API.存储池API.

  5. 2008r2 显示桌面图标

  6. c++ 重载,覆盖,重定义

    写的不是很明白,后来又重新整理过了,在: http://www.cnblogs.com/iois/p/4986790.html 函数重载(Function Overloading) C++允许同一范围 ...

  7. 转:git windows中文 乱码问题解决汇总

    it的Windows版本Msysgit对中文的支持不够好 .当使用时,会出现以下三种情况的中文乱码: 下面的几个文件都在git安装目录下文件夹etc内.1.ls不能显示中文目录 解决办法:在git/g ...

  8. 关于UIText换行

    话不多说,直接上代码 --代码是lua的,c++也一样 local text = ccui.Text:create("text can line wrap text can line wra ...

  9. NVelocity 实例

    using System; using System.IO; using System.Collections; using System.Collections.Generic; using Sys ...

  10. SLF4J warning or error messages and their meanings(转)

    The method o.a.commons.logging.impl.SLF4FLogFactory#release was invoked. Given the structure of the ...