#1184: Connectivity two • Double connected components of the edge

Source: Internet
Author: User

Stick the board. Cut edges. Change > to >= to determine if u is a cut point.

#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;const int inf=0x3f3f3f3f ; const int Maxn=20008;const int maxm=100008;struct fuck{int u,v,next;bool ban;} Edge[maxm<<1];int tol;int head[maxn];void init () {Tol=0;memset (head,-1,sizeof (Head));} void Addedge (int u,int v) {edge[tol].u=u;edge[tol].v=v;edge[tol].next=head[u];edge[tol].ban=false;head[u]=tol++;} int tim=0;int pre[maxn],low[maxn];int tarj (int u,int fa) {int lowu=pre[u]=++tim;int child=0;int i,v,lowv;for (I=head[u]; I!=-1;i=edge[i].next) {v=edge[i].v;if (!pre[v]) {Child++;lowv=tarj (v,u); Lowu=min (LOWU,LOWV); if (Lowv>pre[u]) { Edge[i].ban=true;edge[i^1].ban=true;}} ElseIf (PRE[V]&LT;PRE[U]&AMP;&AMP;V!=FA) lowu=min (Lowu,pre[v]);} Low[u]=lowu;return Lowu;} int Uni[maxn];bool vis[maxn];void DFS (int u,int idx) {int i,v;vis[u]=true;uni[u]=idx;for (I=head[u];i!=-1;i=edge[i]. Next) {if (edge[i].ban| | VIS[EDGE[I].V]) Continue;v=edge[i].v;dfs (V,IDX);}} int main () {int i,j,n,m,u,v;while (scanf ("%d%d", &n,&m) ==2) {iniT (); for (i=1;i<=m;i++) {scanf ("%d%d", &u,&v); Addedge (u,v); Addedge (v,u);} Tim=0;memset (pre,0,sizeof (PRE)), Tarj (1,-1), memset (vis,false,sizeof (VIS)), int ans=0;for (i=1;i<=n;i++) if (!vis[ I]) {DFS (i,i); ans++;} printf ("%d\n", ans), for (i=1;i<=n;i++) {if (i!=1) printf ("");p rintf ("%d", Uni[i]);} printf ("\ n");} return 0;}

#1184: Connectivity two • Double connected components of the edge

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.