📄 dagts.java
字号:
package twf.graph.directed;
import twf.adt.graph.AdjList;
import twf.adt.graph.Graph;
public class DagTS {
private Graph G;
private int []pre, post, postI;
private int cnt, bcnt;
public DagTS(Graph G) {
this.G = G;
pre = new int[G.V()];
post = new int[G.V()];
postI = new int[G.V()];
for (int i = 0; i < G.V(); i++) {
pre[i] = -1;
post[i] = -1;
postI[i] = -1;
}
for (int i = 0; i < G.V(); i++) {
if (pre[i] == -1) {
tsR(i);
}
}
}
private void tsR(int v) {
pre[v] = cnt++;
AdjList A = G.getAdjList(v);
for (int t = A.beg(); !A.end(); t = A.nxt()) {
if (pre[t] == -1) {
tsR(t);
}
}
post[v] = bcnt; postI[bcnt++] = v;
}
public int order(int v) {
return postI[v];
}
public int relabel(int v) {
return post[v];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -