标签:signed imm val sam bool efi cstring ret sse
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 5573 | Accepted: 1818 |
Description
Input
Output
Sample Input
3 3 0 1 0 2 2 1 4 2 0 1 2 3 3 1 1 0 0 0
Sample Output
1 2 2
Source
#include <cstring> #include <ctype.h> #include <cstdio> #define N 20005 void read(int &x) { x=0;char ch=getchar(); for(;!isdigit(ch);ch=getchar()); for(;isdigit(ch);ch=getchar()) x=x*10+ch-‘0‘; } struct Edge { int next,to; Edge (int next=0,int to=0) :next(next),to(to) {} }edge[N<<1]; bool vis[N],cutpoint[N]; int sumcol,ans,head[N],cnt=-1,n,m,dfn[N],low[N],tim; void init() { memset(head,-1,sizeof(head)); cnt=-1; memset(edge,0,sizeof(edge)); ans=0; sumcol=0; tim=0; memset(dfn,0,sizeof(dfn)); memset(vis,0,sizeof(vis)); memset(low,0,sizeof(low)); } void insert(int u,int v) { edge[++cnt]=Edge(head[u],v); head[u]=cnt; } int max(int a,int b) {return a>b?a:b;} int min(int a,int b) {return a>b?b:a;} void tarjan(int x,int pre) { vis[x]=1; low[x]=dfn[x]=++tim; int sum=0; int tot=0; for(int u=head[x];u!=-1;u=edge[u].next) { if(!vis[edge[u].to]) { sum++; tarjan(edge[u].to,x); low[x]=min(low[x],low[edge[u].to]); if(low[edge[u].to]>=dfn[x]) tot++; } else if(dfn[edge[u].to]<dfn[x]&&edge[u].to!=pre) low[x]=min(low[x],dfn[edge[u].to]); } if(pre==-1) {if(sum>1) ans=max(ans,sum-1);} else ans=max(ans,tot); } int main() { while(scanf("%d%d",&n,&m)!=EOF&&(n||m)) { init(); if(m==0) { printf("%d\n",n-1); continue; } for(int x,y;m--;) { read(x); read(y); insert(x,y); insert(y,x); } for(int i=0;i<n;i++) { if(!vis[i]) { sumcol++; tarjan(i,-1); } } printf("%d\n",sumcol+ans); } return 0; }
标签:signed imm val sam bool efi cstring ret sse
原文地址:http://www.cnblogs.com/ruojisun/p/7220215.html