POJ 1144 Network 裸割点

来源:互联网 发布:辐射4 捏脸数据 编辑:程序博客网 时间:2024/06/01 16:21

题意:

给一个图,求割点个数


#include <cstdio>#include <iostream>#include <cstring>using namespace std;const int MAXN = 110;int low[MAXN], dfn[MAXN], head[MAXN], tail, cnt, timer, n;struct Line{ int to, nxt; }line[ MAXN * MAXN ];bool iscut[MAXN];void add_line( int from, int to ) {    line[++tail].nxt = head[from];    head[from] = tail;    line[tail].to = to;}void init(){    memset( head, 0, sizeof( head ) );    memset( iscut, false, sizeof( iscut ) );    memset( dfn, 0, sizeof( dfn ) );    tail = 0; cnt = 0; timer = 0;}void Tarjan( int u ) {    low[u] = ++timer;     dfn[u] = timer;    int child = 0;    for( register int i = head[u]; i; i = line[i].nxt ) {        int v = line[i].to;        if( !dfn[v] ) {            child++;            Tarjan( v );            low[u] = min( low[u], low[v] );            if( low[v] <= u ) iscut[u] = true;        } else low[u] = min( low[u], dfn[v] );    }    if( u == 1 && child == 1 ) iscut[u] = false;}int main( ) {    while( scanf( "%d", &n ) && n ) {        init(); int x, y;         while( scanf( "%d", &x ) && x ) {            while( getchar() != '\n' ) {                scanf( "%d", &y );                add_line( x, y ); add_line( y, x );            }        }        Tarjan( 1 );        for( register int i = 1; i <= n; i++ )             if( iscut[i] ) cnt++;        printf( "%d\n", cnt );    }    return 0;}

这里写图片描述

原创粉丝点击