The number of points to find the longest connection. Use Tarjan to shrink points, thinking that each of the strong connected components of the points are either selected, or do not choose (go other way), can be moved to solve the rules.
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <vector>5#include <cstring>6 using namespacestd;7 Const intmxn=12000;8 intTOP,STACK[MXN];9 BOOLINST[MXN];Ten intCnt,dnow; One intDFN[MXN],LOW[MXN]; A intBELONE[MXN]; - intPTCNT[MXN]; - intDP[MXN]; thevector<int> E[MXN];//adjacency Table -vector<int> PT[MXN];//set of points after shrinking - voidClear () { -Cnt=0;d now=0; top=0; +memset (dfn,-1,sizeof(DFN)); -memset (Inst,false,sizeof(inst)); +Memset (DP,0,sizeofDP); Amemset (ptcnt,0,sizeofptcnt); atmemset (Belone,0,sizeofbelone); - for(intI=1; i<mxn;i++) e[i].clear (); - for(intI=1; i<mxn;i++) pt[i].clear (); - } - intn,m; - voidTarjan (ints) { in intv=0, I; -dfn[s]=++Dnow; tolow[s]=Dfn[s]; +inst[s]=true; -stack[++top]=s; the intSi=e[s].size (); * for(i=0; i<si;i++){ $v=E[s][i];Panax Notoginseng if(dfn[v]==-1){ - Tarjan (v); thelow[s]=min (low[v],low[s]); + } A Else if(Inst[v]) { thelow[s]=min (dfn[v],low[s]); + } - } $ if(dfn[s]==Low[s]) { $cnt++; - Do{ -v=stack[top--]; thebelone[v]=CNT; -inst[v]=false;Wuyi} while(s!=v); the } - return; Wu } - intFindintx) {//Motion Regulation About if(pt[x].size () = =0)returndp[x]=Ptcnt[x]; $ if(Dp[x])returnDp[x]; - intmx=0; - for(intI=0; I<pt[x].size (); i++){ -mx=Max (Mx,find (pt[x][i)); A } +dp[x]=mx+Ptcnt[x]; the returnDp[x]; - } $ voidSolve () {//statistics of connectivity after shrinking points the inti,j,k; the for(i=1; i<=n;i++){ theptcnt[belone[i]]++; the for(j=0; J<e[i].size (); j + +){ - intv=E[i][j]; in if(belone[i]!=Belone[v]) the Pt[belone[i]].push_back (Belone[v]); the } About } the intans=0; the for(i=1; i<=cnt;i++) ans=Max (Ans,find (i)); theprintf"%d\n", ans); + return; - } the intMain () {Bayi intT; thescanf"%d",&T); the while(t--){ -scanf"%d%d",&n,&m); - Clear (); the inti,j; the intu,v; the for(i=1; i<=m;i++){ thescanf"%d%d",&u,&v); - E[u].push_back (v); the } the for(i=1; i<=n;i++) {//Pinch point the if(dfn[i]==-1) Tarjan (i);94 } the solve (); the } the return 0;98}
UVa 11234 the largest clique