poj3694
来源:互联网 发布:java servlet 编辑:程序博客网 时间:2024/05/17 03:31
Description
A network administrator manages a large network. The network consists of N computers and M links between pairs of computers. Any pair of computers are connected directly or indirectly by successive links, so data can be transformed between any two computers. The administrator finds that some links are vital to the network, because failure of any one of them can cause that data can't be transformed between some computers. He call such a link a bridge. He is planning to add some new links one by one to eliminate all bridges.
You are to help the administrator by reporting the number of bridges in the network after each new link is added.
Input
The input consists of multiple test cases. Each test case starts with a line containing two integers N(1 ≤ N ≤ 100,000) and M(N - 1 ≤ M ≤ 200,000).
Each of the following M lines contains two integers A and B ( 1≤ A ≠ B ≤ N), which indicates a link between computer A and B. Computers are numbered from 1 to N. It is guaranteed that any two computers are connected in the initial network.
The next line contains a single integer Q ( 1 ≤ Q ≤ 1,000), which is the number of new links the administrator plans to add to the network one by one.
The i-th line of the following Q lines contains two integer A and B (1 ≤ A ≠ B ≤ N), which is the i-th added new link connecting computer A and B.
The last test case is followed by a line containing two zeros.
Output
For each test case, print a line containing the test case number( beginning with 1) and Q lines, the i-th of which contains a integer indicating the number of bridges in the network after the first i new links are added. Print a blank line after the output for each test case.
Sample Input
3 21 22 321 21 34 41 22 12 31 421 23 40 0
Sample Output
Case 1:10Case 2:20
题意:给你一个连通图,然后再给你n个询问,每个询问给一个点u,v表示加上u,v之后又多少个桥。一个最容易想到的办法就是先加边找桥,加边找桥,这样可定超时。那么就可以缩点,因为如果一条边不是桥那么无论怎么加边他肯定都不会变成桥,这样我吧不是桥的点缩成一个点。这样全图就都是桥,这样的话,我们就在加的遍里面去找如果加的边是同一个点,那么,肯定不会减少桥,但是如果不是同一个,那么桥肯定减少~。
虽然知道思路,但至今还是WA。
WA代码:
var a:array [1..5000,1..500] of longint; i,j,m,n,x,y,z,d,q,ans,t,p,leaf:longint; low,dfn,c,st,bcc:array [1..5000] of longint; b:array [1..10000,1..2] of longint; ff,k:array [1..5000,1..5000] of boolean; f:array [1..5000] of boolean;function min(x,y:longint):longint;begin if x<y then exit(x); exit(y);end;procedure cut(x,y:longint);begin if not k[x,y] then begin ff[y,x]:=false; ff[x,y]:=false; inc(t); end;end;procedure find(x,y:longint);var i,v,xx:longint;begin inc(d); low[y]:=d; dfn[y]:=d; f[y]:=true; for i:=1 to c[y] do if x<>a[y,i] then begin v:=a[y,i]; if not f[v] then begin find(y,v); if low[v]=dfn[v] then cut(y,v); low[y]:=min(low[y],low[v]); end else low[y]:=min(low[y],dfn[v]); end;end;procedure dfs(x:longint);var i:longint;begin f[x]:=true; bcc[x]:=p; for i:=1 to c[x] do if ff[x,a[x,i]] and not f[a[x,i]] then dfs(a[x,i]);end;begin readln(m,n); while (m<>0) and (n<>0) do begin fillchar(c,sizeof(c),0); fillchar(a,sizeof(a),0); fillchar(k,sizeof(k),false); fillchar(ff,sizeof(ff),false); for i:=1 to n do begin readln(x,y); inc(c[x]); inc(c[y]); a[x,c[x]]:=y; a[y,c[y]]:=x; if ff[x,y] then begin k[x,y]:=true; k[y,x]:=true; end; ff[x,y]:=true; ff[y,x]:=true; end; readln(z); for j:=1 to z do begin readln(x,y); inc(c[x]); inc(c[y]); a[x,c[x]]:=y; a[y,c[y]]:=x; if ff[x,y] then begin k[x,y]:=true; k[y,x]:=true; end; ff[x,y]:=true; ff[y,x]:=true; d:=0; t:=0; fillchar(f,sizeof(f),false); for i:=1 to m do if not f[i] then find(-1,i); writeln(t); end; readln(m,n); end;end.
- poj3694
- poj3694
- POJ3694
- poj3694 总结
- POJ3694--Network
- poj3694 Network
- POJ3694----Network
- poj3694 Network
- 【POJ3694】Network
- poj3694 Network
- poj3694 Network
- hdu2460 和 poj3694
- LCA+桥poj3694
- poj3694 连通图+LCA
- poj3694 Network Tarjan+树链剖分
- poj3694(边双联通分量)
- POJ3694 Network 割边+LCA
- poj3694 Network Tarjan(树链剖分)
- 关于用 Masonary实现三个View等间距的实现
- QT进程间通信详细介绍及QProcess机制分析
- PHP成长记(三) —— SSO单点登录/登出
- Java的内存管理
- VC 仿QQ窗口靠边自动收缩隐藏效果
- poj3694
- 大数模板(加减乘除取模开方)
- IOS推送功能的实现
- 你应该知道的一些事情——CSS权重
- coco2dx heap corruption detected by dlfree 闪退的问题
- java.util.ConcurrentModificationException 解决办法
- 大话设计模式之初见(一)
- 【经验】对教务处网站的抓包分析并GET教务处照片
- wdcp 或者 主机宝 或 阿里云一键安装包 再也不用担心 服务器环境搭建了