- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
时间戳:dfn[u] 表示节点 u 深度优先遍历的序号。
追溯点:low[u]表示节点u或u的子孙能通过非父子追溯到dfn最小节点的序号,即回到最早的过去。
初始时,dfn[u]=low[u],如果该节点的邻节点未被访问,则一直进行深度优先遍历,1-2-3-5-6-4,此时 4 的邻接点 1 已被访问,且 1 不是 4 的父节点,4 的父节点是6(深度优先搜索树上的父节点)。
节点 4 能回到最早的节点是节点1(dfn=1),因此low[4]=min(low[4],dfn[1])=1,返回时,更新low[6]=min(low[6],low[4])=1。更新路径上所有祖先节点的 low 值,因为子孙能回到的追溯点,其祖先也能回到。
桥判定法则:无向边 x-y 是桥,当且仅当搜索树上存在一个节点 y,满足 low[y] > dfn[x]。
也就是说,如果孩子的 low 值比自己大,则从该节点到这个孩子的边为桥。在上图中,边5-7中,5的子节点为7,满足 low[7]>dfn[5],因此 5-7 为桥。
package graph.tarjanbridge;
import java.util.Arrays;
import java.util.Scanner;
public class TarjanBridge {
static int SIZE = 100010;
static int head[] = new int[SIZE], to[] = new int[SIZE << 1], next[] = new int[SIZE << 1];
static int cnt = 0;
static void addEdge(int x, int y) {
to[cnt] = y;
next[cnt] = head[x];
head[x] = cnt++;
to[cnt] = x;
next[cnt] = head[y];
head[y] = cnt++;
}
static int dfn[] = new int[SIZE], low[] = new int[SIZE];
static int index;
static boolean bridge[] = new boolean[SIZE << 1];
static void tarjan(int x, int edge) {
dfn[x] = low[x] = ++index;
for (int i = head[x]; i >= 0; i = next[i]) {
int y = to[i];
if (dfn[y] == 0) {
tarjan(y, i);
low[x] = Math.min(low[x], low[y]);
if (dfn[x] < low[y])
bridge[i] = bridge[i ^ 1] = true;
} else if (i != (edge ^ 1))
low[x] = Math.min(low[x], dfn[y]);
}
}
static void init() {
Arrays.fill(head, -1);
cnt = 0;
}
static int n, m;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
init();
for (int i = 0; i < m; i++)
addEdge(sc.nextInt(), sc.nextInt());
for (int i = 1; i <= n; i++)
if (dfn[i] == 0)
tarjan(i, -1);
for (int i = 1; i < cnt; i += 2)
if (bridge[i])
System.out.println(to[i ^ 1] + " " + to[i]);
}
}
我正在阅读命令模式,并且看到来自不同站点的示例,这些示例似乎使用桥+命令模式来展示命令模式。 首先,来自维基百科:https://en.wikipedia.org/wiki/Command_patte
我有一个超低延迟程序,需要与 Windows COM 组件交互。最快的方法是什么?使用像 JACOB 这样的 COM 桥,或者编写 native COM 库并使用像 ZeroMQ 这样的消息传递总线发
我正在开发一个应用程序,该应用程序具有托管在 Glassfish 服务器上的 Java Web 界面和作为 Linux 守护进程实现的 C 内核。 我现在最大的问题是如何进行远程过程调用。我需要双向调
我已经在带有KVM的Fedora 17上设置了VM,并为KVM配置了桥接网络。主机和VM均使用手动IP配置,主机的IP为192.168.0.2,VM的为192.168.0.10。 从VM可以毫无问题地
主 GUI 基于 SWT。我正在通过单击按钮从 printPDF 类运行打印操作。 public void startPDFPrint() throws Exception { Display
我开始尝试使用 SWT-AWT 桥,但我无法为位于 Composite 内的 JPanel 找到合适的尺寸。谁能告诉我代码有什么问题吗? import java.awt.BorderLayout; i
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Troubleshooting ClassNotFoundException when using PHP/
我对 Linux 很陌生,但我正在尽力学习。我们有CentOS 6的专用托管服务器。它配置了Apache服务器作为我们的公共(public)网站。现在我们需要在上面安装 PHP JAVA Bridge
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 2 年前。 Improve this qu
有没有类似铁轨搭桥 Pylons 的脚手架?我一直在搜索谷歌,但只发现了这个叫做 dbsprockets 的东西,这很好,虽然可能对我的需要来说太多了。我真正需要的是基于 SQLAlchemy 模型的
我正在寻找可用于集成任何源代码控制管理系统的通用 git 桥(如 git-svn、git-p4、git-tfs)模板。 如果没有这样的模板,至少有一些关于如何在 git 端集成基本操作的说明(对于其他
我正在开发一个应用程序,我将在 UIWebView 中同时使用 HTML5 和 native iOS 框架。我知道我可以实现 JavaScript 和 Objective-C 之间的通信。是否有任何库
我目前观察到第 3 方库(即 restfb)正在使用 java.util.logging,我看到这些日志最终出现在 STDOUT 中,即使我没有在我的 logback 中配置 SLF4J 控制台附加程
我正在尝试让 aurelia-materialize 桥接插件工作,但到目前为止无法使用 jspm 完成,所以我尝试使用 webpack。我将 typescript-webpack 框架提取到一个文件
我想使用 java 将 SFTP 客户端连接到 FTP 服务器。我知道这两种技术彼此无关。我想要完成的是通过互联网连接到 FTP 服务器,而不使用两个端口或更改服务器配置。 Java 中有 SFTP-
我有 MS Access 数据库文件,文本字段中带有德语变音符号。当我尝试阅读它们时,我有字符串?字符而不是带有变音符号的字符。我尝试为数据库连接设置不同的字符集,例如 properties.setP
我感觉这是 wpf 中的一个错误。让我知道你们对此有何看法。 为了简单起见,我在 .net 4.0 中制作了演示示例 我有一个 ContentControl,其中 Content 绑定(bind)到
我正在尝试让 PHPJAVA 桥在我目前的 Apache2 设置上工作。 虽然,坦率地说,我不知道从哪里开始。 我已经下载了 JavaBridgeTemplate621.war,但不知道放在哪里。 感
我需要在 php 上运行一些 java 代码所以我找到了这个 http://php-java-bridge.sourceforge.net/pjb/index.php 所以我下载了tomcat,把Ja
我正在使用 OrientDb 并希望通过 PHP 运行 Gremlin 命令。有谁知道是否有任何桥梁或产品可以连接这两种语言? 虽然我知道 OrientDB-PHP 和 OrientDB-REST 包
我是一名优秀的程序员,十分优秀!