Gym 100342I Travel Agency

Source: Internet
Author: User

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

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.