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)