Popular Cows---poj2186 (contraction point, strong unicom)

Source: Internet
Author: User

Title Link:http://poj.org/problem?id=2186

Ask how many points meet other n-1 points can reach this point, is a one-way map;

So we can get the graph to be indented, and then find out the number of points contained in the point 0 of the degree is to obtain the answer;

If the degree is more than 0, then the answer is 0;

#include <cstdio>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#include<cstring>#include<vector>#defineN 10010#defineLson r*2#defineRson r*2+1#defineINF 0XFFFFFFFusing namespacestd;intStack[n], top, out[n], time, flag;intNblock, Block[n], dfn[n], low[n], is[n], N, head[n], CNT;structedge{intV, Next;} E[n*N];voidInit () {Nblock= CNT = top = time = Flag =0; memset (Head,-1,sizeof(Head)); memset (Low,0,sizeof(low)); memset (DFN,0,sizeof(DFN)); memset (Block,0,sizeof(Block)); memset (out,0,sizeof(out)); Memset (IS,0,sizeof(IS)); memset (Stack,0,sizeof(Stack));}voidADD (intUintv) {E[CNT].V=v; E[cnt].next=Head[u]; Head[u]=cnt++;}voidTajar (intu) {Dfn[u]=low[u]=++Time ; Is[u]=1; Stack[top++]=u; intv;  for(intI=head[u]; i!=-1; I=E[i].next) {v=e[i].v; if(!Dfn[v])            {Tajar (v); Low[u]=min (Low[u], low[v]); }        Else{Low[u]=min (Low[u], dfn[v]); }    }    if(low[u]==Dfn[u]) {        ++Nblock;  Do{v=stack[--top]; BLOCK[V]=Nblock; } while(u!=v); }}intMain () {intu, V, m;  while(SCANF ("%d%d", &n, &m)! =EOF)        {Init ();  for(intI=0; i<m; i++) {scanf ("%d%d", &u, &v);        ADD (U,V); }         for(intI=1; i<=n; i++)            if(!Low[i])            {Tajar (i); }         for(intI=1; i<=n; i++)        {             for(intJ=head[i]; j!=-1; j=E[j].next) {u=block[i]; v=BLOCK[E[J].V]; if(u!=v) out[u]++; }} Flag=0; intIndex;  for(intI=1; i<=nblock; i++)        {            if(out[i]==0) {flag++; Index=i; }        }        if(flag>1) {printf ("0\n"); Continue; }        intans=0;  for(intI=1; i<=n; i++)        {            if(block[i]==Index) ans++; } printf ("%d\n", ans); }    return 0;}
View Code

Popular Cows---poj2186 (contraction point, strong unicom)

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.