Bzoj 4116 Wf2015 Tours Tarjan

Source: Internet
Author: User

The topic is: given a piece n A point m The side of the graph, you need to select a number of color categories k , and then use this k Color to each edge, requiring that for any simple ring in the graph, the number of edges of each color is the same, all feasible k

Consider the edge set E Split into subsets { E 1 , E 2 , E 3 ,..} That satisfies any simple ring that can be split into subsets and that does not exist after the two subset is merged, then the answer is GCD{| E 1 |,| E 2 |,| E 3 |,..} All the approximate

So how do you determine these subsets?

"Try to delete each non-bridged edge and count how many sides have become new bridges. Get the number of the +1 gcd. "--petr
Tourist brush down the Twitter, the mouth with a touch of mystery, with the Battle of the national atmosphere of the smile. (Giant fog

We try to delete each non-bridge side, then the new side of the bridge must be the same set as the non-bridge, but I will not prove it.

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 2020using namespace STD;structedge{intx, y;} EDGES[M];structabcd{intTo,num,next;} table[m<<1];inthead[m],tot=1;intN,m,ans;intDpt[m],low[m],t;BOOLIS_BRIDGE[M],TO_BE_BRIDGE[M],V[M];voidInitialize () {memset(Head,0,sizeofHead); tot=1;memset(DPT,0,sizeofDPT);memset(Low,0,sizeofLow);memset(To_be_bridge,0,sizeofTo_be_bridge);}voidADD (intXintYintz) {table[++tot].to=y;    Table[tot].num=z;    TABLE[TOT].NEXT=HEAD[X]; Head[x]=tot;}voidTarjan (intXintFrom) {intI Dpt[x]=low[x]=++t; for(I=head[x];i;i=table[i].next)if(i^from^1)        {if(Dpt[table[i].to]) low[x]=min (low[x],dpt[table[i].to]);Else{Tarjan (table[i].to,i); Low[x]=min (low[x],low[table[i].to]);if(Low[table[i].to]>dpt[x]) to_be_bridge[table[i].num]=true; }        }}intMain () {intI,j;Cin>>n>>m; for(i=1; i<=m;i++) {scanf("%d%d", &AMP;EDGES[I].X,&AMP;EDGES[I].Y);        ADD (Edges[i].x,edges[i].y,i);    ADD (Edges[i].y,edges[i].x,i); } for(i=1; i<=n;i++)if(!dpt[i]) Tarjan (I,0);memcpy(Is_bridge,to_be_bridge,sizeofIs_bridge); for(i=1; i<=m;i++)if(!v[i]&&!is_bridge[i]) {intCnt=1; v[i]=true; Initialize (); for(j=1; j<=m;j++)if(j!=i)                    {ADD (EDGES[J].X,EDGES[J].Y,J);                ADD (EDGES[J].Y,EDGES[J].X,J); } for(j=1; j<=n;j++)if(!dpt[j]) Tarjan (J,0); for(j=1; j<=m;j++)if(!is_bridge[j]&&to_be_bridge[j]) v[j]=true, ++cnt;        ANS=__GCD (ANS,CNT); } for(i=1; i<=ans;i++)if(ans%i==0)printf("%d%c", I,i==ans?' \ n ':"');return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bzoj 4116 Wf2015 Tours Tarjan

Related Keywords:

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.