bzoj1093: [ZJOI2007] Maximum semi-connected sub-graph

Source: Internet
Author: User

惨烈啊。。。int son[x]=>bool son[x]一直调不出来我也是醉了。!!!最新错法。。。  缩点后有重边!!! 就是缩点之后找最长路然后找有多少条最长路树形dp一下。
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> #include <stack > Using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) #define QWQ (x) for (Edge *o=head[x];o;o=o->next) #define QAQ (x) for (edge *o=h[x];o;o=o->next) int read ()     {int X=0,f=1;char c=getchar ();    while (!isdigit (c)) {if (c== '-') F=-1;c=getchar ();     } while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x*f; } const int nmax=1e5+5; const int maxn=1e6+5; const int inf=0x7f7f7f7f; struct edge{int to;edge *next;}; Edge es[maxn<<1],*pt=es,*head[nmax]; void Add (int u,int v) {pt->to=v;pt->next=head[u];head[u]=pt++;} int pre[nmax],scc[nmax],size[nmax],dfs_clock,s Cc_cnt,mod; stack<int>s;     void mins (int &a,int b) {if (a>b) a=b;} void maxs (int &a,int b) {if (a<b) a=b;} int dfs (int x) { int Lowu=pre[x]=++dfs_clock;s.puSH (x);         QWQ (x) {if (!pre[o->to]) mins (Lowu,dfs (o->to));     else if (!scc[o->to]) mins (lowu,pre[o->to]);         } if (Lowu==pre[x]) {Scc_cnt++;int o,cnt=0;             while (1) {o=s.top (); S.pop ();             scc[o]=scc_cnt;cnt++;         if (o==x) break;     } size[scc_cnt]=cnt; } return LOWU; } Edge *h[nmax]; BOOL Vis[nmax];int Son[nmax],sum[nmax],orz[nmax];     void Adde (int u,int v) {pt->to=v;pt->next=h[u];h[u]=pt++;} void Dfs (int x) {vis[x]=1;int cnt=0;     Qaq (x) {if (!vis[o->to]) Dfs (o->to); Maxs (Cnt,son[o->to]); } Son[x]=cnt+size[x];    } void DFS (int x) {vis[x]=1;         Qaq (x) {if (!vis[o->to]) DFS (o->to);     if (son[x]==son[o->to]+size[x]&&orz[o->to]!=x) sum[x]= (Sum[x]+sum[o->to])%mod,orz[o->to]=x; } if (!h[x]) sum[x]=1;     } int main () {int n=read (), M=read (), U,v;mod=read ();     Rep (i,1,m) U=read (), V=read (), add (U,V); Rep (I,1,n)if (!pre[i]) DFS (i);            Rep (i,1,n) printf ("%d", Scc[i]);p rintf ("\ n");         Rep (i,1,n) {u=scc[i];     QWQ (i) if (U!=scc[o->to]) Adde (U,scc[o->to]);     } int ans=0;     Rep (i,1,scc_cnt) if (!vis[i]) Dfs (i), Maxs (Ans,son[i]);     Rep (i,1,scc_cnt) printf ("%d", Son[i]);p rintf ("\ n");     int res=0;clr (vis,0);     Rep (i,1,scc_cnt) if (!vis[i]) {if (Son[i]==ans) DFS (i), res= (Res+sum[i])%mod;     } printf ("%d\n%d\n", ans,res); return 0;  }

  

1093: [ZJOI2007] Maximum half-connected sub-graph time limit:30 Sec Memory limit:162 MB
submit:2725 solved:1079
[Submit] [Status] [Discuss]
Description

A undirected graph g= (v,e) is called a semi-connected (semi-connected), if satisfied: U,v∈v, satisfies u→v or v→u, that is, for any
Two point u,v, there is a forward path from U to V or a path from V to U. If g ' = (v ', E ') satisfies V '? V,e ' is all the side of E in relation to V ',
is called G ' is an export sub-chart of G. If G ' is the derived sub-graph of G, and G ' is semi-connected, then G ' is a semi-connected sub-graph of G. If G ' is g all semi-connected sub-graphs
Contains the largest number of nodes, the "G" is the maximum half-connected sub-graph of G. Given a graph G, the maximum number of nodes that a request out of G is owned by the largest semi-connected sub-graph K
, and the number of different maximum semi-connected sub-graphs C. Because C can be larger, only the remainder of the output C to X is required.

Input

The first line consists of two integer n,m,x. N,m represents the number of points and sides of the graph G, and the meaning of x is the next M-line, two positive integers per line, as described above
Number A, B, indicates a forward edge (A, B). Each point in the figure is numbered ... N, ensure that the same (a, b) in the input does not occur two times. N≤1
00000, m≤1000000; for 100% of data, x≤10^8

Output

Should contain two lines, the first line containing an integer k. The second line contains the integer c Mod X.

Sample Input6 6 20070603
1 2
2 1
1 3
2 4
5 6
6 4
Sample Output3
3
HINT Source [Submit] [Status] [Discuss]

bzoj1093: [ZJOI2007] Maximum semi-connected sub-graph

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.