zoukankan      html  css  js  c++  java
  • kuangbin专题 专题九 连通图 Network UVA

    题目链接:https://vjudge.net/problem/UVA-315

    题目:求割点。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 const int N = 110;
     7 int n,tim,tot,root = 1;
     8 int head[N],dfn[N],low[N],poi[N];
     9 struct node{
    10     int to;
    11     int nxt;
    12 }e[N*N];
    13 
    14 void init(){
    15     for(int i = 0; i <= n; ++i){
    16         head[i] = -1;
    17         dfn[i] = poi[i] = 0;
    18     }
    19     tim = tot = 0;
    20 }
    21 
    22 inline void add(int u,int v){
    23     e[tot].to = v;
    24     e[tot].nxt = head[u];
    25     head[u] = tot++;
    26 }
    27 
    28 void tarjan(int now,int pre){
    29     dfn[now] = low[now] = ++tim;
    30     int to,son = 0;
    31     for(int o = head[now]; ~o; o = e[o].nxt){
    32         to = e[o].to;
    33         if(to == pre) continue; //处理无向图的双向边问题
    34         if(!dfn[to]){
    35             ++son;
    36             tarjan(to,now);
    37             low[now] = min(low[now],low[to]);
    38             //割点条件1
    39             if(now != root && dfn[now] <= low[to]) poi[now] = 1;
    40         }
    41         else if(low[now] > dfn[to]) low[now] = dfn[to];
    42     }
    43     //割点条件2
    44     if(now == root && son >= 2) poi[now] = 1;
    45 }
    46 
    47 int main(){
    48 
    49     int u,v;
    50     char ch;
    51 
    52     while(~scanf("%d",&n) && n){
    53         init();
    54 
    55         while(~scanf("%d",&u) && u){
    56             while(~scanf("%d%c",&v,&ch)){
    57                 add(u,v); add(v,u);
    58                 if(ch == '
    ') break;
    59             }
    60         }
    61         tarjan(1,1);
    62         int ans = 0;
    63         for(int i = 0; i <= n; ++i)
    64             if(poi[i]) ++ans;
    65 
    66         printf("%d
    ",ans);
    67     }
    68 
    69 
    70     return 0;
    71 }
  • 相关阅读:
    JDK的几种分析工具
    心理价值
    通过Proxool辅助数据库优化
    人生缄言
    grep 用法
    多服务器快速定位
    RandomAccessFile读取远程系统日志
    20101116 视频处理几个常用指令
    Flickr架构
    JAVA正则表达式语法
  • 原文地址:https://www.cnblogs.com/SSummerZzz/p/12194336.html
Copyright © 2011-2022 走看看