Test instructions read the good to do, is to ask for a point of dual connectivity components. Maintain the node number of a subtree, for a node when u is a cut point,
To count the connected component V of the U-segment, multiply the number of nodes CNT (v) from each connected component and the sum of the previous connected component nodes. Finally, add the sum of the total number of connected components on the subtree and the other nodes.
B,c in which accesses than either can be a, and all the last to add n-1.
Fill in the previous question
#include <bits/stdc++.h>using namespacestd;intn,m;Const intMAXN =20005; Vector<int>G[MAXN];#definePB push_backintDFN[MAXN],LOW[MAXN],DFS_CLOCK,ANS[MAXN],CNT[MAXN];voidTarjan (intUintFA =-1) {Dfn[u]= Low[u] = + +Dfs_clock; Cnt[u]=1; Ans[u] =0; intsum =0; for(inti =0; I < g[u].size (); i++){ intv =G[u][i]; if(!Dfn[v]) {Tarjan (V,FA); if(low[v]>=Dfn[u]) {Ans[u]+ = sum*Cnt[v]; Sum+=Cnt[v]; } Low[u]=min (low[v],low[u]); Cnt[u]+=Cnt[v]; }Else if(v! = FA && Dfn[v] < Dfn[u]) {Low[u] =min (low[u],dfn[v]);} } Ans[u]+ = (n-sum-1)*sum;}intMain () {Freopen ("travel.in","R", stdin); Freopen ("Travel.out","W", stdout); CIN>>n>>m; for(inti =0; I < m; i++){ intU,v; scanf"%d%d",&u,&v); G[u]. PB (v); G[V]. PB (U); } Tarjan (1); for(inti =1; I <= N; i++) printf ("%d\n", ans[i]+n-1); return 0;}
Gym 100342I Travel Agency