Uva-11324the Largest clique |
Test instructions: Find the node set with the largest number of nodes, so that any two nodes can be at least from one to the other
The same SCC must be selected for a select-all
To construct a new graph for SCC contraction point get a DAG, direct DP line up
This new figure does not require a heavy edge, but a heavy edge is a real existence.
////main.cpp//largest group////Created by Candy on 02/11/2016.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#defineC (x) memset (x,0,sizeof (x))using namespacestd;Const intn=1e3+5, m=5e4+5; inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intt,n,m,u,v;structedge{intV,ne;} E[M];intH[n],cnt=0; inlinevoidInsintUintv) {CNT++; E[CNT].V=v;e[cnt].ne=h[u];h[u]=CNT;}intDfn[n],low[n],belong[n],dfc,scc,size[n];intSt[n],top;voidDfsintu) {Dfn[u]=low[u]=++DFC; st[++top]=u; for(intI=h[u];i;i=e[i].ne) { intv=e[i].v; if(!Dfn[v]) {DFS (v); Low[u]=min (low[u],low[v]); }Else if(!Belong[v]) Low[u]=min (low[u],dfn[v]); } if(low[u]==Dfn[u]) {SCC++; while(true){ intx=st[top--]; BELONG[X]=SCC; SIZE[SCC]++; if(X==u) Break; } }}voidSCC () {DFC=scc=0; C (DFN); C (Low); C (belong); C (size); Top=0; for(intI=1; i<=n;i++)if(!Dfn[i]) DFS (i);} Edge Es[n];inths[n],cs=0; inlinevoidInssintUintv) {CS++; ES[CS].V=v;es[cs].ne=hs[u];hs[u]=CS;}voidbuildgraph () {CS=0; C (HS); for(intu=1; u<=n;u++){ intA=Belong[u]; for(intI=h[u];i;i=e[i].ne) { intb=BELONG[E[I].V]; if(a!=b) Inss (a); } }}intF[n];intdpintu) { if(f[u]!=-1)returnF[u]; F[u]=Size[u]; intmx=0; for(intI=hs[u];i;i=es[i].ne) { intV=ES[I].V;//printf ("DP%d v%d\n", u,v);mx=Max (MX,DP (v)); } returnf[u]+=MX;}intMainintargcConst Char*argv[]) {T=read (); while(t--) {n=read (); m=read (); CNT=0; Memset (H,0,sizeof(h)); for(intI=1; i<=m;i++) {u=read (); v=read (); Ins (u,v);} SCC (); Buildgraph (); Memset (F,-1,sizeof(f)); intans=0; for(intI=1; i<=scc;i++){ if(f[i]==-1) DP (i); Ans=Max (ans,f[i]); } printf ("%d\n", ans); } return 0;}
UVA11324 the largest clique[strong connected component indent DP]