POJ 3352(Tarjen中Low的性质)
来源:互联网 发布:辐射4无mod捏脸数据 编辑:程序博客网 时间:2024/05/16 17:35
这题做了半天……结果发现自己缩点错了……
言归正传,这题给了一个无向图G,求添加几条边后双连通……
做了一上午Tarjen不对……Low就是不满足性质(后来发现这是无向图的,要用有向图版本……——用有向图法做无向图……)
终于……做完了(请忽略Stack,我最后索性直接用Low值了……勉强算hash?)
Program P3352;const maxn=1000; maxm=1000;var n,m,i,j,x,y:longint; b:array[1..maxn,1..maxn] of boolean; indegree,c,stack,a,low:array[1..maxn] of longint; size,time:longint;function min(a,b:longint):longint;begin if a<b then exit(a) else exit(b);end;function max(a,b:longint):longint;begin if a>b then exit(a) else exit(b);end;procedure swap(a,b:longint);var p:longint;begin p:=a; a:=b; b:=p;end;procedure tarjan(k,father{,deep}:longint);var i,j:longint;begin inc(size); stack[size]:=k; //for suo_dian^_^ inc(time); a[k]:=time; low[k]:=time; { low[k]:=deep; a[k]:=deep; } c[k]:=1; for i:=1 to n do begin if (b[i,k]) and (i<>father) and (a[i]<a[k]) then begin if c[i]=0 then begin tarjan(i,k{,deep+1}); low[k]:=min(low[k],low[i]); end; if (c[i]=1) and (i<>father) then begin low[k]:=min(low[k],a[i]); end; end; end; c[k]:=2;end;procedure main;var i,j,tot:longint;begin fillchar(stack,sizeof(stack),0); fillchar(a,sizeof(a),0); fillchar(low,sizeof(low),0); fillchar(c,sizeof(c),0); fillchar(indegree,sizeof(indegree),0); size:=0;time:=0; tarjan(1,0{,1}); for i:=1 to n do for j:=i+1 to n do if (low[i]<>low[j]) and (b[i,j]) then begin inc(indegree[low[i]]); inc(indegree[low[j]]); end; tot:=0; for i:=1 to n do if indegree[i]=1 then inc(tot); writeln((tot+1) div 2);end;beginwhile not seekeof dobegin fillchar(b,sizeof(b),false); read(n,m); for i:=1 to m do begin read(x,y); b[x,y]:=true; b[y,x]:=true; end; main;end;end.
- POJ 3352(Tarjen中Low的性质)
- POJ 2942(Tarjen的点双连通分量+交叉染色法)
- POJ 2406(KMP中next的性质)
- tarjen
- poj 2406 KMP算法中next的一个性质
- 折半(二分查找)中,使用int mid = low+((high-low)>>>1)的原因
- POJ 2551 简单数学(取模的性质)
- [ACM] POJ 2442 Sequence (堆的性质)
- C++中继承的性质
- POJ 1961 HDU 1358 KMP的性质
- poj 3233(等比矩阵的性质)
- POJ 2406(KMP next数组性质)
- poj 1696 Space Ant(叉积的性质,做极角排序)
- poj 1696 Space Ant(叉积的性质,做极角排序)
- poj 2480 Longge's problem(欧拉函数的性质)
- POJ 3150 Cellular Automaton(矩阵快速幂+特殊矩阵的性质)
- POJ 2773 Happy 2006 【gcd的性质(也可用欧拉函数)】
- 子模的性质(submodular)
- 第二章---变量和基本类型
- 排序算法的重要评价标准
- 调试socket(linux下的C)出现:warning: overflow in implicit constant conversion
- 中国移动校园WLAN客户端及使用方法
- 如何掌握程序语言
- POJ 3352(Tarjen中Low的性质)
- 斜率优化
- 0644
- linux 中df和du命令的区别
- 学习shell, 正则表达式, awk, sed
- java集合----------List
- const对象与const成员函数
- 编程通用好书
- 人不能两次踏进同一条河流