填坑……链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1123
题意:问切断第i个点之后多少对点不再联通。
就是个求割点同时计算出双连通分量大小嘛……
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 const int maxn=100005,maxm=500005; 7 struct node 8 { 9 int from,to,next; 10 }edge[maxm<<1]; 11 int head[maxn],tot; 12 void addedge(int u,int v) 13 { 14 edge[++tot]=(node){u,v,head[u]};head[u]=tot; 15 } 16 int low[maxn],dfn[maxn],belong[maxn],cnt,bcnt,size[maxn],n,m; 17 bool iscut[maxn]; 18 long long sum[maxn]; 19 #include<vector> 20 #include<stack> 21 stack<node>s;vector<int>bcc[maxn]; 22 void dfs(int root,int pa) 23 { 24 low[root]=dfn[root]=++cnt; 25 int son=0;size[root]=1;long long su=0; 26 for(int i=head[root];i;i=edge[i].next) 27 { 28 int v=edge[i].to; 29 if(!dfn[v]) 30 { 31 s.push(edge[i]);son++; 32 dfs(v,root);low[root]=min(low[root],low[v]); 33 size[root]+=size[v]; 34 if(low[v]>=dfn[root]) 35 { 36 sum[root]+=su*size[v];su+=1ll*size[v]; 37 iscut[root]=1;bcnt++;bcc[bcnt].clear(); 38 node x;int u=-1,va=-1; 39 do 40 { 41 x=s.top();s.pop(); 42 u=edge[i].from,va=edge[i].to; 43 if(belong[u]!=bcnt)bcc[bcnt].push_back(u),belong[u]=bcnt; 44 if(belong[va]!=bcnt)bcc[bcnt].push_back(va),belong[va]=bcnt; 45 }while(u!=root&&va!=v); 46 } 47 } 48 else if(dfn[v]<dfn[root]&&v!=pa) 49 { 50 s.push(edge[i]); 51 low[root]=min(low[root],dfn[v]); 52 } 53 } 54 if(pa<0&&son==1)iscut[root]=0; 55 sum[root]+=su*(n-su-1); 56 } 57 int haha() 58 { 59 scanf("%d%d",&n,&m); 60 for(int i=1;i<=m;i++) 61 { 62 int x,y;scanf("%d%d",&x,&y); 63 addedge(x,y);addedge(y,x); 64 } 65 for(int i=1;i<=n;i++) 66 if(!dfn[i])dfs(i,-1); 67 for(int i=1;i<=n;i++)printf("%lld\n",1ll*(sum[i]+n-1)*2); 68 } 69 int sb=haha(); 70 int main(){;}
bzoj1123
时间: 2024-10-09 16:58:00