Tarjan算法就不说了

想学看这

https://www.byvoid.com/blog/scc-tarjan/

https://www.byvoid.com/blog/biconnect/

下面是几份基本的模版

首先是无向图割点桥的代码

下面的代码是用于求割点数目的

其中add_block[u] = x  表示删除u点之后增加的联通块个数。注意是增加的联通块个数

const int MAXN = ;
const int MAXM = ;
const int INF = 0x3f3f3f3f;
struct Edge
{
int u,v,next;
int w;
bool cut;
}edge[MAXN];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN];
int Index,top;
bool Instack[MAXN];
bool cut[MAXN];
int add_block[MAXN];
int N,bridge; void init()
{
tot = ;
memset(head,-,sizeof(head));
} void add_edge(int u,int v,int w)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
v = edge[i].v;
if (v == pre) continue;
if (!DFN[v])
{
son++;
Tarjan(v,u);
if (Low[u] > Low[v]) Low[u] = Low[v];
if (Low[u] > DFN[v])
{
bridge++;
edge[i].cut = true;
edge[i ^ ].cut = true;
}
if (u != pre && Low[v] >= DFN[u])
{
cut[u] = true;
add_block[u]++;
}
}
else if (Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (u == pre && son > ) cut[u] = true;
if (u == pre) add_block[u] = son - ;
Instack[u] = false;
top--;
} void slove()
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(cut,false,sizeof(cut));
memset(add_block,,sizeof(add_block));
top = Index = ;
bridge = ;
for (int i = ; i <= N ; i++)
if (!DFN[i]) Tarjan(i,i);
int ret = ;
for (int i = ; i <= N ; i++)
if (cut[i]) ret++;
printf("%d\n",ret);
}

下面的代码仍然是无向图模版。适用于缩点存储。

其中联通块编号为1-bcc。Belong[u] = x;

表示u位于第x个联通块

const int MAXN = ;
const int MAXM = ;
int N,M;
struct Edge
{
int u,v,w;
int next;
// int id;
bool cut;
}edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top;
int block;
bool Instack[MAXN];
int bridge; void init()
{
tot = ;
memset(head,-,sizeof(head));
} void add_edge(int u,int v,int w,int id = )
{
edge[tot].u = u;
edge[tot].v = v;
// edge[tot].id = id;
edge[tot].cut = false;
edge[tot].next = head[u];
head[u] =tot++;
} void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Instack[u] = true;
Stack[top++]= u;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if (v == pre) continue;
if (!DFN[v])
{
Tarjan(v,u);
if (Low[u] > Low[v]) Low[u] = Low[v];
if (Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i ^ ].cut = true;
}
}
else if (Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (Low[u] == DFN[u])
{
block++;
do
{
v = Stack[--top];
Instack[v] = false;
Belong[v] = block;
}while (u != v);
}
} int deg[MAXN];
void calcu(int N)
{
memset(Instack,false,sizeof(Instack));
memset(DFN,,sizeof(DFN));
Index = top = bridge = block = ;
for (int i = ; i <= N ; i++)
{
if (!DFN[i]) Tarjan(i,i);
}
int ret = ;
memset(deg,,sizeof(deg));
for (int u = ; u <= N; u++)
{
for (int i = head[u]; i != - ; i = edge[i].next)
{
if (edge[i].cut == false) continue;
//int v = edge[i].v;
deg[Belong[u]]++;
}
}
for (int i = ; i <= block ; i++)
if (deg[i] == ) ret++;
printf("%d\n",(ret + ) / );
}

下面是在含有重边图中求桥。这里特殊说明一下

正常的tarjan求桥的dfs有两个参数x和fa,其中参数fa就是用于判定某边(x,t)是不是刚刚走过来的边.
在有重边的情形下,这样判就不太方便了...
于是我们修改这个判定条件,把参数fa改为刚刚走过来的这条边的编号.
这就没问题了.至于具体的实现,由于一条无向边拆成两条有向边存下来的时候,编号是连续的,因此像类似4,5这样的两条边,可以通过判断4/2==5/2来判定是否是由同一条无向边拆出来的。

比如下图

该图是没有桥的。然而用以上的版来求就会有问题。下面是正确的求法

边结构体里的id注意一条无向边的2个分开有向边的编号一样

Edge edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN];
int Index,top;
bool Instack[MAXN];
bool cut[MAXN];
int add_block[MAXN];
int bridge; void init()
{
memset(head,-,sizeof(head));
tot = ;
} void add_edge(int u,int v,LL w,int id)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].id = id;
edge[tot].next = head[u];
edge[tot].cut = false;
head[u] = tot++;
} void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
v = edge[i].v;
if (!DFN[v])
{
son++;
Tarjan(v,edge[i].id);
if (Low[u] > Low[v]) Low[u] = Low[v];
if (Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i ^ ].cut = true;
}
if (pre != - && Low[v] >= DFN[u])
{
cut[u] = true;
add_block[u]++;
}
}
else if (DFN[v] < DFN[u] && edge[i].id != pre)
Low[u] = min(Low[u],DFN[v]);
}
/*
if (Low[u] == DFN[u])
{
block++;
do
{
v = Stack[--top];
Instack[v] = true;
Belong[v] = block;
}while (v != u);
}
*/
if (pre == - && son > ) cut[u] = true;
if (pre == -) add_block[u] = son - ;
Instack[u] = false;
top--;
}

接下来是有向图强联通的相关模版。强联通分量标号从1-scc

其中num[x] = i 表示x号强联通分量的点的个数为i

const int MAXN = ;
const int MAXM = MAXN * MAXN;
const int INF = 0x3f3f3f3f;
struct Edge
{
int u,v,next;
int w;
}edge[MAXM];
int N;
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top;
int scc;
bool Instack[MAXN];
int degin[MAXN],degout[MAXN];
int num[MAXN]; void init()
{
tot = ;
memset(head,-,sizeof(head));
} void add_edge(int u,int v,int w)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if (!DFN[v])
{
Tarjan(v);
if (Low[u] > Low[v]) Low[u] = Low[v];
}
else if (Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (Low[u] == DFN[u])
{
scc++;
do
{
v = Stack[--top];
Instack[v] = false;
Belong[v] = scc;
num[scc]++;
}while (v != u);
}
} void slove()
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(num,,sizeof(num));
memset(degin,,sizeof(degin));
memset(degout,,sizeof(degout));
Index = top = ;
scc = ;
for (int i = ; i <= N ; i++)
if (!DFN[i]) Tarjan(i);
for (int i = ; i < tot ; i++)
{
int u = Belong[edge[i].u];
int v = Belong[edge[i].v];
if (u == v) continue;
degout[u]++;
degin[v]++;
}
//for (int i = 1 ; i <= N ; i++) printf("%d ",Belong[i]); putchar('\n');
int ansl = ,ansr = ;
for (int i = ; i <= scc ; i++)
if (degin[i] == ) ansl++;
else if (degout[i] == ) ansr++;
int ret = max(ansl,ansr);
if (scc == ) ret = ;
printf("%d\n%d\n",ansl,ret);
}

下面是全部Kuangbin联通图的几题的题解

POJ 1236 Network of Schools

题目大意:有N个学校,从每个学校都能从一个单向网络到另外一个学校,两个问题
1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件。
2:至少需要添加几条边,使任意向一个学校发放软件后,经过若干次传送,网络内所有的学校最终都能得到软件。

首先第一问就是有多少个强联通分量的入度为0;

第二问就是max(出度为0的点的个数,入度为0的点的个数)

第一问很容易发现答案。第二问原因首先就是缩点之后相当于形成了一棵树。最优的肯定是出度为0的叶子节点和入度为0的

跟相连最优。则max就是答案。下面代码

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = MAXN * MAXN;
const int INF = 0x3f3f3f3f;
struct Edge
{
int u,v,next;
int w;
}edge[MAXM];
int N;
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top;
int scc;
bool Instack[MAXN];
int degin[MAXN],degout[MAXN];
int num[MAXN]; void init()
{
tot = ;
memset(head,-,sizeof(head));
} void add_edge(int u,int v,int w)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if (!DFN[v])
{
Tarjan(v);
if (Low[u] > Low[v]) Low[u] = Low[v];
}
else if (Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (Low[u] == DFN[u])
{
scc++;
do
{
v = Stack[--top];
Instack[v] = false;
Belong[v] = scc;
num[scc]++;
}while (v != u);
}
} void slove(int n)
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(num,,sizeof(num));
memset(degin,,sizeof(degin));
memset(degout,,sizeof(degout));
Index = top = ;
scc = ;
for (int i = ; i <= N ; i++)
if (!DFN[i]) Tarjan(i);
for (int i = ; i < tot ; i++)
{
int u = Belong[edge[i].u];
int v = Belong[edge[i].v];
if (u == v) continue;
degout[u]++;
degin[v]++;
}
//for (int i = 1 ; i <= N ; i++) printf("%d ",Belong[i]); putchar('\n');
int ansl = ,ansr = ;
for (int i = ; i <= scc ; i++)
if (degin[i] == ) ansl++;
else if (degout[i] == ) ansr++;
int ret = max(ansl,ansr);
if (scc == ) ret = ;
printf("%d\n%d\n",ansl,ret);
} int main()
{
while (scanf("%d",&N) != EOF)
{
init();
for (int i = ; i <= N ; i++)
{
int x;
while (scanf("%d",&x) != EOF)
{
if (x == ) break;
add_edge(i,x,);
}
}
slove(N);
}
return ;
}

Uva 315 Network 求割点个数

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = ;
const int INF = 0x3f3f3f3f;
struct Edge
{
int u,v,next;
int w;
bool cut;
}edge[MAXN];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN];
int Index,top;
bool Instack[MAXN];
bool cut[MAXN];
int add_block[MAXN];
int N,bridge; void init()
{
tot = ;
memset(head,-,sizeof(head));
} void add_edge(int u,int v,int w)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
v = edge[i].v;
if (v == pre) continue;
if (!DFN[v])
{
son++;
Tarjan(v,u);
if (Low[u] > Low[v]) Low[u] = Low[v];
if (Low[u] > DFN[v])
{
bridge++;
edge[i].cut = true;
edge[i ^ ].cut = true;
}
if (u != pre && Low[v] >= DFN[u])
{
cut[u] = true;
add_block[u]++;
}
}
else if (Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (u == pre && son > ) cut[u] = true;
if (u == pre) add_block[u] = son - ;
Instack[u] = false;
top--;
} void slove()
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(cut,false,sizeof(cut));
memset(add_block,,sizeof(add_block));
top = Index = ;
bridge = ;
for (int i = ; i <= N ; i++)
if (!DFN[i]) Tarjan(i,i);
int ret = ;
for (int i = ; i <= N ; i++)
if (cut[i]) ret++;
printf("%d\n",ret);
} int main()
{
while (scanf("%d",&N) != EOF)
{
if (N == ) break;
init();
int u,v;
while (scanf("%d",&u) != EOF)
{
if (u == ) break;
char ch;
while (scanf("%d%c",&v,&ch) != EOF)
{
add_edge(u,v,);
add_edge(v,u,);
if (ch == '\n') break;
}
}
slove();
}
return ;
}

POJ 3694 Newwork

有一个可重边的无向图。Q个询问每次向其加边。输出每次加边之后的无向图桥的个数

首先直接干是应该不能过的。不过听说数据很水可以过。。

做法:首先缩点形成一个树。于是树上的所有边就是桥,那么每次加边首先判断是不是在一个双联通里

如果在那么不需要更新直接输出桥即可。否则两边在树上向上找LCA即可。路过的树边如果之前没有标记为不是桥

那么就更新答案。这里我自己写的无穷WA。至今不知为何。学了Kuangbin神的写法。这个代码不是标记边

而是标记桥的终点是否已经被删除,代码就看把。LCA并不是用很高深的方法求的(实际我不会)

就一层一层的向上找

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = ;
struct Edge
{
int u,v,w;
int next;
int id;
bool cut;
}edge[MAXM];
int head[MAXN],tot;
int N,M;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top;
int block;
bool Instack[MAXN];
int bridge; void init()
{
tot = ;
memset(head,-,sizeof(head));
} void add_edge(int u,int v,int w,int id)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].id = id;
edge[tot].cut = false;
edge[tot].next = head[u];
head[u] =tot++;
} void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
v = edge[i].v;
if (!DFN[v])
{
son++;
Tarjan(v,edge[i].id);
if (Low[u] > Low[v]) Low[u] = Low[v];
if (Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i ^ ].cut = true;
}
}
else if (DFN[v] < DFN[u] && edge[i].id != pre)
Low[u] = min(Low[u],DFN[v]);
}
if (Low[u] == DFN[u])
{
block++;
do
{
v = Stack[--top];
Instack[v] = true;
Belong[v] = block;
}while (v != u);
}
} vector<int>vec[MAXN];
int father[MAXN],dep[MAXN],a[MAXN];
void LCA_bfs(int root)
{
memset(dep,-,sizeof(dep));
dep[root] = ;
a[root] = ;
father[root] = -;
queue<int>q;
q.push(root);
while (!q.empty())
{
int u = q.front(); q.pop();
for (int i = ; i < (int)vec[u].size() ; i++)
{
int v = vec[u][i];
if (dep[v] != -) continue;
dep[v] = dep[u] + ;
a[v] = ;
father[v] = u;
q.push(v);
}
}
} int ret;
void lca(int u,int v)
{
if (dep[u] > dep[v]) swap(u,v);
while (dep[u] < dep[v])
{
if (a[v])
{
ret--;
a[v] = ;
}
v = father[v];
}
while (u != v)
{
if (a[u])
{
ret--;
a[u] = ;
}
if (a[v])
{
ret--;
a[v] = ;
}
u = father[u];
v = father[v];
}
} void calcu(int N)
{
memset(Instack,false,sizeof(Instack));
memset(DFN,,sizeof(DFN));
Index = top = block = ;
bridge = ;
for (int i = ; i <= N ; i++)
if (!DFN[i]) Tarjan(i,-);
for (int i = ; i <= N ; i++)
vec[i].clear();
for (int u = ; u <= N ; u++)
{
for (int i = head[u] ; i != - ; i = edge[i].next)
{
if (edge[i].cut == false) continue;
int v = edge[i].v;
vec[Belong[u]].push_back(Belong[v]);
vec[Belong[v]].push_back(Belong[u]);
}
}
// printf("%d\n",bridge);
LCA_bfs();
ret = block - ;
int Q;
scanf("%d",&Q);
while (Q--)
{
int u,v;
scanf("%d%d",&u,&v);
lca(Belong[u],Belong[v]);
printf("%d\n",ret);
}
putchar('\n');
} int main()
{
// freopen("sample.txt","r",stdin);
int kase = ;
while (scanf("%d%d",&N,&M) != EOF)
{
if (N == && M == ) break;
printf("Case %d:\n",kase++);
init();
for (int i = ; i < M ; i++)
{
int u,v;
scanf("%d%d",&u,&v);
add_edge(u,v,,i);
add_edge(v,u,,i);
}
calcu(N);
}
return ;
}

POJ 3177 Redundant Paths

题意:最少添加几条边使得全图双联通即无桥

做法:缩点形成树。直接所有叶子节点之间相互连边肯定是最优的。那么ans=(leaf + 1) / 2;

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = ;
int N,M;
struct Edge
{
int u,v,w;
int next;
// int id;
bool cut;
}edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top;
int block;
bool Instack[MAXN];
int bridge; void init()
{
tot = ;
memset(head,-,sizeof(head));
} void add_edge(int u,int v,int w,int id = )
{
edge[tot].u = u;
edge[tot].v = v;
// edge[tot].id = id;
edge[tot].cut = false;
edge[tot].next = head[u];
head[u] =tot++;
} void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Instack[u] = true;
Stack[top++]= u;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if (v == pre) continue;
if (!DFN[v])
{
Tarjan(v,u);
if (Low[u] > Low[v]) Low[u] = Low[v];
if (Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i ^ ].cut = true;
}
}
else if (Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (Low[u] == DFN[u])
{
block++;
do
{
v = Stack[--top];
Instack[v] = false;
Belong[v] = block;
}while (u != v);
}
} int deg[MAXN];
void calcu(int N)
{
memset(Instack,false,sizeof(Instack));
memset(DFN,,sizeof(DFN));
Index = top = bridge = block = ;
for (int i = ; i <= N ; i++)
{
if (!DFN[i]) Tarjan(i,i);
}
int ret = ;
memset(deg,,sizeof(deg));
for (int u = ; u <= N; u++)
{
for (int i = head[u]; i != - ; i = edge[i].next)
{
if (edge[i].cut == false) continue;
//int v = edge[i].v;
deg[Belong[u]]++;
}
}
for (int i = ; i <= block ; i++)
if (deg[i] == ) ret++;
printf("%d\n",(ret + ) / );
} int main()
{
while (scanf("%d%d",&N,&M) != EOF)
{
init();
while (M--)
{
int u,v;
scanf("%d%d",&u,&v);
add_edge(u,v,);
add_edge(v,u,);
}
calcu(N);
}
return ;
}

HDU 4612 Warm up

加一条边使得加这条边的新图的桥最少。

首先由上一题POJ 3177 肯定知道缩点后连叶子节点肯定更优。问题就变成了找哪2个叶子节点连边

第一次遇到这个问题的时候是gym 100002 记得。当时我的做法就暴力枚举叶子节点N*N,然后倍增找的最优方案

复杂度不过。后来发现最优的就是这个缩点形成的树的最长链,这条最长链在树边全部是桥的树上删除的树是最多的

那么就是如何找最长连。很简单。2次DFS,第一次DFS,直接找最深的点,这个点记为u。那么接下来在一次DFS,从

u DFS找到最深(无向图会回到树根然后再找另一个最深)这个深度就处理出了删除桥的个数

另外本题要手工扩栈

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
inline int readint()
{
char c = getchar();
while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
return x;
}
const int MAXN = ;
const int MAXM = MAXN * ;
const int INF = 0x3f3f3f3f;
struct Edge
{
int u,v,w;
int next;
int id;
bool cut;
}edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top,block,bridge;
bool vis[MAXN];
bool Instack[MAXN];
int N,M; void init()
{
memset(head,-,sizeof(head));
tot = ;
} void add_edge(int u,int v,int w,int id)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].id = id;
edge[tot].cut = false;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
v = edge[i].v;
if (!DFN[v])
{
son++;
Tarjan(v,edge[i].id);
if (Low[u] > Low[v]) Low[u] = Low[v];
if (Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i ^ ].cut = true;
}
}
else if (DFN[v] < DFN[u] && edge[i].id != pre)
Low[u] = min(Low[u],DFN[v]);
}
if (Low[u] == DFN[u])
{
block++;
do
{
v = Stack[--top];
Instack[v] = true;
Belong[v] = block;
}while (v != u);
}
} int pos,maxdep,ret;
vector<int>vec[MAXN]; void dfs(int cur,int fa,int curdep)
{
vis[cur] = true;
if (curdep > maxdep)
{
maxdep = curdep;
pos = cur;
}
for (int i = ; i < (int)vec[cur].size() ; i++)
{
int v = vec[cur][i];
if (vis[v] || v == fa) continue;
dfs(v,cur,curdep + );
}
} void calcu(int N)
{
for (int i = ; i <= N ; i++) Instack[i] = false;
for (int i = ; i <= N ; i++) DFN[i] = ;
Index = top = bridge = block = ;
for (int i = ; i <= N ; i++)
{
if (!DFN[i]) Tarjan(i,-);
}
for (int i = ; i <= block ; i++) vec[i].clear();
for (int u = ; u <= N ; u++)
{
for (int i = head[u] ; i != - ; i = edge[i].next)
{
if (edge[i].cut == false) continue;
int u = Belong[edge[i].u];
int v = Belong[edge[i].v];
vec[u].push_back(v);
vec[v].push_back(u);
}
}
maxdep = ;
for (int i = ; i < block + ; i++) vis[i] = false;
dfs(,-,);
ret = ;
for (int i = ; i < block + ; i++) vis[i] = false;
maxdep = ;
dfs(pos,-,);
printf("%d\n",bridge - maxdep);
} int main()
{
while (scanf("%d%d",&N,&M) != EOF)
{
if (N == && M == ) break;
init();
for (int i = ; i <= M ; i++)
{
int u,v;
u = readint();
v = readint();
add_edge(u,v,,i);
add_edge(v,u,,i);
}
calcu(N);
}
return ;
}

HDU 4635 Strongly connected

题意:最多添加几条边使得图仍然不是强联通的。还有一些其他情况,具体读题把!

这题很厉害啊;

首先我们可以分析。加完边之后的图是什么样子的

首先其必然不是强联通的。要加尽量多的边,相当与分成2个部分我们另它们分别为U,V;

另外我们知道如果边尽量多且不是双联通。那么就全部U联通分量的点都连出一条有向边到V;

U内强联通且V内强联通便最多。这时候的边的数目就是num[u] * num[v] + num[u] * (num[u] - 1) +

num[v] * (num[v] - 1);

这样问题转换成了

在这样的图中和起始给与边M的最大差,下面我分析下上面那个式子

由均值不等式且numu + numv == N(点数)是必然的那么我定义U部点个数为x,V部点个数为y

就有x + y = N;

最后的边的个数是x * y + x * (x - 1) + y * (y - 1) = x * y + x * x * y * y - x - y =

(x + y) ^ 2 - xy - x - y = N^2 - N - xy;到了这里就能发现x与y差距越大那么边数越大

假设只有入度或者出度为0的才可能成为U部,V部。那么代码就如下

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = ;
struct Edge
{
int u,v,next;
int w;
}edge[MAXM];
int head[MAXN],tot;
LL Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top;
int scc;
LL N,M;
bool Instack[MAXN];
LL num[MAXN]; void init()
{
tot = ;
memset(head,-,sizeof(head));
} void add_edge(int u,int v,int w)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
v = edge[i].v;
if (!DFN[v])
{
Tarjan(v);
if (Low[u] > Low[v]) Low[u] = Low[v];
}
else if (Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (Low[u] == DFN[u])
{
scc++;
do
{
v = Stack[--top];
Instack[v] = false;
Belong[v] = scc;
num[scc]++;
}while (v != u);
}
} LL degin[MAXN];
LL degout[MAXN];
void calcu(LL N,int kase)
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(num,,sizeof(num));
memset(degin,,sizeof(degin));
memset(degout,,sizeof(degout));
Index = scc = top = ;
for (int i = ; i <= N ; i++)
if (!DFN[i]) Tarjan(i);
if (scc == )
{
printf("Case %d: -1\n",kase);
return;
}
for (int i = ; i < tot ; i++)
{
int u = Belong[edge[i].u];
int v = Belong[edge[i].v];
if (u == v) continue;
degin[v]++;
degout[u]++;
}
LL tmp = N * (N - ) - M;
LL ret = ;
for (int i = ; i <= scc ; i++)
{
if (degin[i] == || degout[i] == )
{
ret = max(ret,(N - num[i]) * num[i] +(num[i] - ) * num[i]
+ (N - num[i] - ) * (N - num[i]) - M);
}
}
printf("Case %d: %d\n",kase,ret);
} int main()
{
int T,kase = ;
scanf("%d",&T);
while (T--)
{
init();
scanf("%I64d%I64d",&N,&M);
for (int i = ; i < M ; i++)
{
int u,v;
scanf("%d%d",&u,&v);
add_edge(u,v,);
}
calcu(N,kase++);
}
return ;
}

HDU 4685 Prince and Princess

这题太吊了。反着我是完全不会。题解代码均是看了别人的。悟把!

复制的:

对于这个题,首先我们考虑一个简化版,即如同样例给出来的有 个王
子和公主,并且他们能够完全匹配的情况。
我们先求出最大匹配,这时我们如果对于每个王子和他喜欢的每个公
主都去枚举他们 link 的时候是否还能找到最大匹配,这样复杂度可能高达
4),应该是会超时的。
那么我们换一个角度,枚举然后找最大匹配实质上是找到一个人和他互
换,并且他们喜欢他们互相配对的公主。那么我们可以试着直接用连边来
表示这个过程,对于每个王子,从他目前配对的公主出发连有向边到他喜
欢的所有公主,表示他配对的公主单方面可以和这些公主换。若是两者可
以互换,那么在图中就表示为了可以互相到达,从而想到对于这样的一个
图求出他的强连通分量,对于每个王子,枚举他喜欢的每个公主,如果这
个公主和他目前配对的公主在同一个强连通分量里,表示这个王子可以选
该公主。
然后回到这个题,这个题变成了 个王子和 个公主,其实最主要的
还是他们的最大匹配不一定是完全匹配。如果直接套用以上的方法就有问
题。比如有一个王子,两个公主,这个王子两个公主都喜欢,那么求出的
最大匹配只会和其中一个公主相连,通过上面的方法建图,两个公主并不
会在一个强连通分量里面,但实际上这个王子选两个中的任意一个都不会
使最大匹配减少。我们要怎么解决这个问题,这里又要从最本质的地方来
看,就是一个互换。
这里的王子如果求出匹配连的是一号公主,那么二号公主没有和任何王
子相连,这个王子就无法和任何人互换从而得到二号公主。考虑到这个问
题,很自然的就能想到给二号公主虚拟一个王子和她配对就好了,然后这
个虚拟的王子喜欢所有的公主。
因为这个公主本身是没有匹配的,如果通过虚拟一个喜欢所有公主的王
子向所有其他公主连边,使得这个公主得到了一个匹配,那么肯定会有另
外一边的匹配数减少了,因为最开始就求到的是最大匹配,如果这个公主
匹配增加并且没有任何一边的匹配减少,肯定违背了最大匹配的性质。
所以得证这样一种虚拟王子连边的方法不会减少匹配数并且正确。
剩下公主的问题考虑完了,现在考虑剩下王子的问题。同理,我们给每
一个没有匹配上的剩下的王子,虚拟一个公主,这个公主被所有王子喜欢,
那么和最开始的做法一样求强连通然后考虑是否在一个强连通分量里即可。

证明和剩下公主类似。

代码

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
int un,vn;
int N,M;
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
bool dfs(int u)
{
for (int v = ; v <= vn ; v++)
{
if (g[u][v] && !used[v])
{
used[v] = true;
if (linker[v] == - || dfs(linker[v]))
{
linker[v] = u;
return true;
}
}
}
return false;
} int hungry()
{
int res = ;
memset(linker,-,sizeof(linker));
for (int u = ; u <= un ; u++)
{
memset(used,false,sizeof(used));
if (dfs(u)) res++;
}
return res;
} int lx[MAXN];
const int MAXM = ;
struct Edge
{
int u,v,w;
int next;
}edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,top;
int scc;
bool Instack[MAXN];
int num[MAXN]; void init()
{
memset(head,-,sizeof(head));
tot = ;
} void add_edge(int u,int v,int w)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u)
{
int v;
Low[u] = DFN[u] = ++Index;
Instack[u] = true;
Stack[top++] = u;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if (!DFN[v])
{
Tarjan(v);
if (Low[u] > Low[v]) Low[u] = Low[v];
}
else if (Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (Low[u] == DFN[u])
{
scc++;
do
{
v = Stack[--top];
Instack[v] = false;
Belong[v] = scc;
num[scc]++;
}while (v != u);
}
} void calcu(int N)
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(num,,sizeof(num));
Index = top = ;
for (int i = ; i <= N ; i++)
{
if (!DFN[i]) Tarjan(i);
}
} int main()
{
int kase = ,T;
scanf("%d",&T);
while (T--)
{
scanf("%d%d",&N,&M);
memset(g,,sizeof(g));
for (int i = ; i <= N ; i++)
{
int cnt;
scanf("%d",&cnt);
while (cnt--)
{
int x;
scanf("%d",&x);
g[i][x] = ;
}
}
un = N;
vn = M;
int res = hungry();
un = vn = N + M - res;
for (int i = N + ; i <= un ; i++)
for (int j = ; j <= vn ; j++)
g[i][j] = ;
for (int i = ; i <= un ; i++)
for (int j = M + ; j <= vn ; j++)
g[i][j] = ;
hungry();
memset(lx,-,sizeof(lx));
for (int i = ; i <= vn ; i++)
{
if (linker[i] != -)
lx[linker[i]] = i;
}
init();
for (int i = ; i <= un ; i++)
for (int j = ; j <= vn ; j++)
{
if (g[i][j] && j != lx[i])
{
add_edge(lx[i],j,);
}
}
calcu(vn);
printf("Case #%d:\n",kase++);
vector<int>ans;
for (int i = ; i <= N ; i++)
{
ans.clear();
for (int j = ; j <= M ; j++)
{
if (g[i][j] && Belong[j] == Belong[lx[i]])
ans.push_back(j);
}
int sz = ans.size();
printf("%d",sz);
for (int i = ; i < sz ; i++)
printf(" %d",ans[i]);
putchar('\n');
}
}
return ;
}

HDU 4738 Caocao's Bridges

这个题就是很坑,不废话看了代码就知道坑在那

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = ;
const int INF = 0x3f3f3f3f;
int fa[MAXN];
int Find(int x){return x == fa[x] ? x : fa[x] = Find(fa[x]);}
struct Edge
{
int u,v,next;
int w;
int id;
bool cut;
}edge[MAXM];
int head[MAXN],tot; void init()
{
tot = ;
memset(head,-,sizeof(head));
} void add_edge(int u,int v,int w,int id)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].id = id;
edge[tot].cut = false;
edge[tot].next = head[u];
head[u] = tot++;
} int Low[MAXN],DFN[MAXN],Stack[MAXN];
int Index,top;
bool Instack[MAXN];
int bridge,N,M; void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
v = edge[i].v;
if (edge[i].id == pre) continue;
if (!DFN[v])
{
son++;
Tarjan(v,edge[i].id);
if (Low[u] > Low[v]) Low[u] = Low[v];
if (Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i ^ ].cut = true;
}
}
else if (DFN[v] < DFN[u] && edge[i].id != pre)
Low[u] = min(Low[u],DFN[v]);
}
/*
if (Low[u] == DFN[u])
{
block++;
do
{
v = Stack[--top];
Instack[v] = true;
Belong[v] = block;
}while (v != u);
}
*/
Instack[u] = false;
top--;
} void calcu(int N)
{
memset(Instack,false,sizeof(Instack));
memset(DFN,,sizeof(DFN));
Index = top = bridge = ;
for (int i = ; i <= N ; i++)
if (!DFN[i]) Tarjan(i,-);
int ret = INF;
for (int i = ; i < tot ; i++)
{
if (edge[i].cut)
ret = min(ret,edge[i].w);
}
if (ret == INF) printf("%d\n",-);
else printf("%d\n",max(,ret));
} int main()
{
while (scanf("%d%d",&N,&M) == )
{
if (N == && M == ) break;
for (int i = ; i <= N ; i++) fa[i] = i;
init();
for (int i = ; i <= M ; i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
add_edge(u,v,w,i);
add_edge(v,u,w,i);
int fu = Find(u);
int fv = Find(v);
if (fu != fv)
{
fa[fu] = fv;
}
}
int id = Find();
bool flag = false;
for (int i = ; i <= N ; i++)
{
int fi = Find(i);
if (fi != id)
{
flag = true;
break;
}
}
if (flag) puts("");
else calcu(N);
}
return ;
}

以上是全部Kuangbin带你飞联通图题目

下面其他的

Gym 100338 C Important Roads

题意就是一个图。让你求出所有最短路中一定要走的路;就是最短路的干路

起初没想到是tarjan 做法就是最短路处理后重建图。跑桥就可以注意重边

同时处理出最短路树也是参照了别人的做法这么搞很有技巧!

代码

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = ;
const LL INF = (1LL << );
struct Edge
{
int u,v,next;
LL w;
int id;
bool cut;
}; struct node
{
LL val;
int u;
bool operator < (const node & rhs) const
{
return val > rhs.val;
}
}; struct Dijkstra
{
int N,M;
LL dis[MAXN];
bool done[MAXN];
int head[MAXN],tot;
Edge edge[MAXM]; void init(int n)
{
memset(head,-,sizeof(head));
tot = ;
N = n;
} void add_edge(int u,int v,LL w,int id)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].id = id;
edge[tot].next = head[u];
head[u] = tot++;
} void dijkstra(int s)
{
memset(done,false,sizeof(done));
for (int i = ; i <= N ; i++) dis[i] = INF;
dis[s] = ;
priority_queue<node>q;
while (!q.empty()) q.pop();
q.push((node){dis[s],s});
while (!q.empty())
{
node x = q.top(); q.pop();
int u = x.u;
// cout << u << " " << dis[u] << endl ;
if (done[u]) continue;
done[u] = true;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if (dis[v] > dis[u] + edge[i].w)
{
dis[v] = dis[u] + edge[i].w;
q.push((node){dis[v],v});
}
}
}
}
}S,T; Edge edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN];
int Index,top;
bool Instack[MAXN];
bool cut[MAXN];
int add_block[MAXN];
int bridge; void init()
{
memset(head,-,sizeof(head));
tot = ;
} void add_edge(int u,int v,LL w,int id)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].id = id;
edge[tot].next = head[u];
edge[tot].cut = false;
head[u] = tot++;
} void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
v = edge[i].v;
if (!DFN[v])
{
son++;
Tarjan(v,edge[i].id);
if (Low[u] > Low[v]) Low[u] = Low[v];
if (Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i ^ ].cut = true;
}
if (pre != - && Low[v] >= DFN[u])
{
cut[u] = true;
add_block[u]++;
}
}
else if (DFN[v] < DFN[u] && edge[i].id != pre)
Low[u] = min(Low[u],DFN[v]);
}
if (pre == - && son > ) cut[u] = true;
if (pre == -) add_block[u] = son - ;
Instack[u] = false;
top--;
} set<int>ans;
set<int>::iterator it; void slove(int N)
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(add_block,,sizeof(add_block));
memset(cut,false,sizeof(cut));
Index = top = bridge = ;
Tarjan(,-);
// printf("%d\n",bridge);
ans.clear();
for (int i = ; i < tot ; i++)
{
if (edge[i].cut)
ans.insert(edge[i].id);
}
printf("%d\n",ans.size());
for (it = ans.begin() ; it != ans.end() ; it++)
printf("%d ",*it);
} int u[MAXN],v[MAXN];
LL w[MAXN];
int main()
{
freopen("important.in","r",stdin);
freopen("important.out","w",stdout);
int n,m,s,t;
while (scanf("%d%d",&n,&m) != EOF)
{
s = ;
t = n;
S.init(n);
T.init(n);
for (int i = ; i <= m ; i++)
{
scanf("%d%d%I64d",&u[i],&v[i],&w[i]);
S.add_edge(u[i],v[i],w[i],i);
S.add_edge(v[i],u[i],w[i],i);
T.add_edge(u[i],v[i],w[i],i);
T.add_edge(v[i],u[i],w[i],i);
}
S.dijkstra(s);
T.dijkstra(t);
init();
for (int i = ; i <= m ; i++)
{
int tu = u[i];
int tv = v[i];
LL tw = w[i];
if ((S.dis[tu] + tw == S.dis[tv] && T.dis[tv] + tw == T.dis[tu])
||(S.dis[tv] + tw == S.dis[tu] && T.dis[tu] + tw == T.dis[tv]))
{
add_edge(tu,tv,tw,i);
add_edge(tv,tu,tw,i);
}
}
slove(n);
}
return ;
}

Tarjan 联通图 Kuangbin 带你飞 联通图题目及部分联通图题目的更多相关文章

  1. 「kuangbin带你飞」专题十七 AC自动机

    layout: post title: 「kuangbin带你飞」专题十七 AC自动机 author: "luowentaoaa" catalog: true tags: - ku ...

  2. 【算法系列学习三】[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 反向bfs打表和康拓展开

    [kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的 ...

  3. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

  4. 「kuangbin带你飞」专题十四 数论基础

    layout: post title: 「kuangbin带你飞」专题十四 数论基础 author: "luowentaoaa" catalog: true tags: mathj ...

  5. 「kuangbin带你飞」专题二十 斜率DP

    layout: post title: 「kuangbin带你飞」专题二十 斜率DP author: "luowentaoaa" catalog: true tags: mathj ...

  6. 「kuangbin带你飞」专题二十二 区间DP

    layout: post title: 「kuangbin带你飞」专题二十二 区间DP author: "luowentaoaa" catalog: true tags: - ku ...

  7. 「kuangbin带你飞」专题十九 矩阵

    layout: post title: 「kuangbin带你飞」专题十九 矩阵 author: "luowentaoaa" catalog: true tags: mathjax ...

  8. 「kuangbin带你飞」专题十八 后缀数组

    layout: post title: 「kuangbin带你飞」专题十八 后缀数组 author: "luowentaoaa" catalog: true tags: - kua ...

  9. 「kuangbin带你飞」专题十二 基础DP

    layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...

随机推荐

  1. Hadoop2.5.2集群部署(完全分布式)

    环境介绍 硬件环境 CPU 4 MEM 4G 磁盘 60G  软件环境 OS:centos6.5版本 64位 Hadoop:hadoop2.5.2 64位 JDK: JDK 1.8.0_91 主机配置 ...

  2. 九度OJ--Q1166

    import java.text.DecimalFormat;import java.util.Scanner; /* * 题目描述: * 立方根的逼近迭代方程是 y(n+1) = y(n)*2/3 ...

  3. TF-IDF与主题模型 - NLP学习(3-2)

    分词(Tokenization) - NLP学习(1) N-grams模型.停顿词(stopwords)和标准化处理 - NLP学习(2) 文本向量化及词袋模型 - NLP学习(3-1) 在上一篇博文 ...

  4. 小心!FOMO3D的坑

    null 01 前方高能 近日,区块链机构安比(SECBIT)实验室审计后确认,FOMO3D游戏的智能合约存在随机数漏洞可被利用,FOMO3D合约及所有抄袭源码的山寨合约均存在该安全漏洞. 原本设计上 ...

  5. BZOJ 3998 TJOI2015 弦论 后缀自动机+DAG上的dp

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3998 题意概述:对于一个给定长度为N的字符串,求它的第K小子串是什么,T为0则表示不同位置 ...

  6. HashMap和Hashtable的区别(转载)

    转载声明:转载自原文http://www.importnew.com/7010.html HashMap和Hashtable的比较是Java面试中的常见问题,用来考验程序员是否能够正确使用集合类以及是 ...

  7. 修改CodeSmith中的SchemaExplorer.MySQLSchemaProvider

    修改C:\Program Files (x86)\CodeSmith\v6.5\Samples\Projects\CSharp\MySQLSchemaProvider\MySQLSchemaProvi ...

  8. jetty maven插件

    <plugins>   <plugin>    <groupId>org.eclipse.jetty</groupId>    <artifact ...

  9. Xcode & swift

    swift-apps swift 2018 apps Xcode Swift Playground https://developer.apple.com/download/ https://deve ...

  10. NOIP2010 codevs1069 洛谷P1525 关押罪犯

    Problem Description S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极 不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用 ...