"ZJOI2004" sniffer

Source: Internet
Author: User

Practice Tarjian good question, even wa a few times after finally will remember Tarjian template

Original question:

An army engaged in information counter-combat exercises. The Reds successfully invaded the Blues ' internal network. The Blue Army has two information centres. The Reds plan to install a sniffer on an intermediate server to hear all the information exchanged between the two information centers. But the Blues ' network is quite large, Packets from one information center to another can have more than one path. Now you need to solve the problem as soon as possible. Which server should I install the sniffer on to ensure that all packets are captured?

1<=n<=100000

Well, first of all can be determined that the answer must be a point in the top of the cut, necessity: Because the deletion of the point S and T are not connected, so this point is a cut point, but this condition is not sufficient, such as the following figure:

1 is also cut the top, but after the deletion of 1 s and T is still connected, that is, a cutting top may not be in the S to T must be on the road

However, the Tarjian DFN and low can not only be used to find the cutting top and strong connectivity components, the use is quite extensive

Procedure: In Tarjian, if a point x is connected to the other end of an edge of X (Y, satisfies x!=s && low[y]>=dfn[x] && dfn[y]<=dfn[t] && low[t] >=DFN[X]

The meanings of these four conditions are: X of course, the s;x is not a cut point; Y to traverse before T, T go to the second path to X (these conditions are a bit strange, the blind disregard is good =)

A few other conditions are well understood, y to traverse before T, that is low[y]>=dfn[x] this condition I think for a long time (and try to right)

Why:

Adequacy: If x is traversed after y, then Y has passed a path from S to T (that is, the DFS path to Tarjian), and after deleting X, the s can still pass through this path to t,x, which is not the desired point.

And then the Tarjian template is spicy.

Tip: Because you want the smallest answer, you don't have to save the answer, Ans=min (ans,x);

Does it seem to be possible to use a fee stream? Split, in and out of the weight between the value of 1, the cost is the number of points, the original edge of the weight of Oo, from S to t cost flow, as if it is right?

Code:

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <cmath>6 using namespacestd;7 intRead () {intz=0, mark=1;CharCh=GetChar ();8      while(ch<'0'|| Ch>'9'){if(ch=='-') mark=-1; Ch=GetChar ();}9      while(ch>='0'&&ch<='9') {z= (z<<3) + (z<<1) +ch-'0'; Ch=GetChar ();}Ten     returnz*Mark; One } A structddd{intNext,y;} e[2100000];intlink[110000],ltop=0; -InlinevoidInsertintXintY) {e[++ltop].next=link[x]; link[x]=ltop;e[ltop].y=y;} - intn,s,t; the intdfn[110000],low[110000],dfs_cnt=0; - BOOLvisited[110000]; - intans=999999999; - voidTarjian (intXint_father) { +visited[x]=true; -dfn[x]=low[x]=++dfs_cnt; +      for(intI=link[x];i;i=E[i].next) { A         if(!Visited[e[i].y]) { at Tarjian (e[i].y,x); -low[x]=min (low[x],low[e[i].y]); -             if(X!=s && low[e[i].y]>=dfn[x] && dfn[e[i].y]<=dfn[t] && low[t]>=dfn[x]) ans=min (ans,x); -         } -         Else if(E[i].y!=_father) low[x]=min (low[x],dfn[e[i].y]); -     } in } - intMain () { toFreopen ("ddd.in","R", stdin); +Freopen ("Ddd.out","W", stdout); -Memset (visited,0,sizeof(visited)); theCin>>N; *     int_left,_right; $      for(;;) {Panax Notoginseng_left=read (), _right=read (); -         if(!_left &&!_right) Break; the Insert (_left,_right), insert (_right,_left); +     } ACin>>s>>T; theTarjian (s),0); +     if(ans>n) cout<<"No Solution"<<Endl; -     Elsecout<<ans<<Endl; $     return 0; $}
View Code

"ZJOI2004" sniffer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.