【POJ1144】Network(割点)(模板)

题意:给定一张无向图,求割点个数

思路:感谢CC大神http://ccenjoyyourlife.blog.163.com/的讲解

割点的定义就是某个联通块中删去此点连通性发生变化的的点

有两种割点:1.U为树根,子树个数>1

2.U非树根,有U的子节点V满足low[v]>=dfn[u]表示U的V子树必须通过U去到U的上面

更新时也有两种:dfn[u]<dfn[v]时u--->v 实边 反则u--->v 虚边

实边时low[u]=min(low[u],low[v]) 虚边low[u]=min(low[u],dfn[v])

 1 var head,vet,next,low,dfn,b,son,flag:array[1..50000]of longint;
 2     n,m,x,i,tot,time,ans:longint;
 3
 4 procedure add(a,b:longint);
 5 begin
 6  inc(tot);
 7  next[tot]:=head[a];
 8  vet[tot]:=b;
 9  head[a]:=tot;
10 end;
11
12 function min(x,y:longint):longint;
13 begin
14  if x<y then exit(x);
15  exit(y);
16 end;
17
18 procedure dfs(u:longint);
19 var e,v:longint;
20 begin
21  flag[u]:=1;
22  inc(time); low[u]:=time; dfn[u]:=time;
23  e:=head[u];
24  while e<>0 do
25  begin
26   v:=vet[e];
27   if flag[v]=0 then
28   begin
29    inc(son[u]);
30    dfs(v);
31    low[u]:=min(low[u],low[v]);
32    if (low[v]>=dfn[u])and(u<>1) then b[u]:=1;
33   end
34    else low[u]:=min(low[u],dfn[v]);
35   e:=next[e];
36  end;
37 end;
38
39 begin
40  assign(input,‘1.in‘); reset(input);
41  assign(output,‘1.out‘); rewrite(output);
42  repeat
43   readln(n);
44   if n=0 then break;
45   fillchar(head,sizeof(head),0);
46   fillchar(low,sizeof(low),0);
47   fillchar(dfn,sizeof(dfn),0);
48   fillchar(flag,sizeof(flag),0);
49   fillchar(son,sizeof(son),0);
50   fillchar(b,sizeof(b),0);
51   repeat
52    read(m);
53    while not eoln do
54    begin
55     read(x);
56     add(x,m);
57     add(m,x);
58    end;
59   until m=0;
60   time:=0;
61   for i:=1 to n do
62    if flag[i]=0 then dfs(i);
63   ans:=0;
64   for i:=2 to n do if b[i]=1 then inc(ans);
65   if son[1]>1 then inc(ans);
66   writeln(ans);
67  until n=0;
68  close(input);
69  close(output);
70 end.
时间: 2024-12-28 07:50:09

【POJ1144】Network(割点)(模板)的相关文章

Poj 1144 Zoj 1311 求割点 模板

写这个就是为了手写一份好用的求割点模板: 吐槽下,题目中的 Each of the next at most N lines contains the number of a place followed by the numbers of some places to which there is a direct line from this place.  这个at most是不可信的,应该是用大于n行的测试数据,因为这个我WA了... #include <cstdio> #includ

割点-模板

洛谷割点模板:https://www.luogu.org/problemnew/show/P3388 #include <iostream> #include <cstring> #include <string> #include <algorithm> #include <cstdio> #include <vector> using namespace std; const int maxn = 100009; vector&l

Tarjan求强连通分量、求桥和割点模板

Tarjan 求强连通分量模板.参考博客 #include<stdio.h> #include<stack> #include<algorithm> using namespace std; const int maxn = 1e3 + 10; const int maxm = 330000 + 10; struct EDGE{ int v, nxt; }Edge[maxm]; int Head[maxn], cnt; int DFN[maxn], LOW[maxn],

【连通图|割点】POJ-1144 Network

Network Time Limit: 1000MS Memory Limit: 10000K Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The li

poj1144 Network【tarjan求割点】

转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4319585.html   ---by 墨染之樱花 [题目链接]http://poj.org/problem?id=1144 [题目描述](半天才看明白...)给图求割点个数 [思路]直接套求割点的模板即可,就是要注意输入比较坑.代码见下,附注释 #include <iostream> #include <ios> #include <iomanip> #includ

POJ1144 Network(判断割点)

题目链接"点击打开链接 判断割点的个数 #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <queue> #include <algorithm> const int N = 210; const int maxn = 500; const int maxm = 21010; const int inf =

POJ1144 Network 题解 点双连通分量(求割点数量)

题目链接:http://poj.org/problem?id=1144 题目大意:给以一个无向图,求割点数量. 这道题目的输入和我们一般见到的不太一样. 它首先输入 \(N\)(\(\lt 100\))表示点的数量(\(N=0\)表示文件输入结束). 然后接下来每行输入一组数字. 如果这一组数字只包含一个 \(0\) ,说明本组测试数据输入结束: 否则,假设这些数可以拆分成 \(a_1,a_2,a_3, \cdots ,a_m\),则说明 \(a_1\) 这个点到 \(a_2,a_3, \cdo

poj 1144 Network(割点 入门)

Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10907   Accepted: 5042 Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N

[POJ1144]Network

来源:Central Europe 1996 思路:Tarjan求割点. 一个点$x$为割点当且仅当: 1.$x$为根结点且有两棵不相交的子树. 2.$x$不为根结点且它的子树中没有可以返回到$x$的祖先的边. 实现细节: 当$x$为根结点时,不能单纯地统计它的度,而是应该统计其不相交子树的个数,因为如果刚好是一个环,每个点的度都是$2$,但去掉这个点以后还是连通的. 1 #include<cstdio> 2 #include<vector> 3 #include<cstri

poj1144Network (求割点模板题)

题目连接 题意:给出一个无向图,求出割点的个数 code: #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> #define maxn 100005 using namespace std; vector<int> G[maxn]; int dfn[maxn],vis[maxn],low[max