Uva 315 Network 判断割点

模板题,注意输出

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <stack>
using namespace std;
typedef long long LL;
const int N = 1e2+5;
int head[N],tot,n;
struct Edge{
   int v,next;
}edge[N*N];
bool iscut[N];
void add(int u,int v){
   edge[tot].v=v;
   edge[tot].next=head[u];
   head[u]=tot++;
}
int dfn[N],low[N],clk;
void targin(int u,int f){
   dfn[u]=low[u]=++clk;
   int child=0;
   for(int i=head[u];~i;i=edge[i].next){
       int v=edge[i].v;
       if(v==f)continue;
       if(!dfn[v]){
         ++child;
         targin(v,u);
         low[u]=min(low[u],low[v]);
         if(f!=-1&&low[v]>=dfn[u])iscut[u]=true;
       }
       else if(dfn[v]<low[u])low[u]=dfn[v];
   }
   if(f==-1&&child>1)iscut[u]=true;
}
int main(){
    while(~scanf("%d",&n),n){
      memset(head,-1,sizeof(head));clk=tot=0;
      for(int u;;){
        scanf("%d",&u);
        if(!u)break;
        for(int v;;){
          scanf("%d",&v);
          add(u,v);
          add(v,u);
          char c=getchar();
          if(c==‘\n‘)break;

        }
      }
      memset(iscut,false,sizeof(iscut));
      memset(dfn,0,sizeof(dfn));
      memset(low,0,sizeof(low));
      for(int i=1;i<=n;++i)
       if(!dfn[i])targin(i,-1);
      int ans=0;
      for(int i=1;i<=n;++i)
       if(iscut[i])++ans;
       printf("%d\n",ans);
    }
    return 0;
}

时间: 2024-08-01 08:42:27

Uva 315 Network 判断割点的相关文章

UVA - 315 Network 和 UVA - 10199 (求割顶)

链接 :  http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20837 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21278 求割顶的裸题. UVA - 315 #include <algorithm> #include <iostream> #include <sstream> #include <cstrin

uva 315 Network(连通图求割点)

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=251  Network  A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers

UVA 315 Network(无向图求割点)

题目大意 A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N. No two places have the same number. The lines are bidirectional and always connect together two pl

UVA - 315 Network(tarjan求割点的个数)

题目链接:https://vjudge.net/contest/67418#problem/B 题意:给一个无向连通图,求出割点的数量.首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第一个数字代表后面的都和它存在边,0表示行输入的结束. 题解:简单的求割点模版,所谓割点就是去掉这一个点还有于这个点链接的边之后使得原来的图连通块增加. 由于这是模版题代码会加上注释. #include <iostream> #include <cstring> using namesp

POJ 1144 &amp; Uva 315 Network 【求割点数目】

Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10855   Accepted: 5020 链接:http://poj.org/problem?id=1144 Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places

B - Network - uva 315(求割点)

题意:给一个无向连通图,求出割点的数量. 首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第一个数字代表后面的都和它存在边,0表示行输入的结束(很蛋疼的输入方式). 分析:割点的模板题 ****************************************************************** #include<stdio.h>#include<string.h>#include<stack>#include<algorith

无向图求割点 UVA 315 Network

输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> #include <vector> #include <queue> #include <cmath> #include <stack> #include <cstring> using namespa

Network UVA - 315 无向图找割点

题意: 给你一个无向图,你需要找出来其中有几个割点 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<queue> 6 using namespace std; 7 const int maxn=105; 8 int cnt,head[maxn],n,dfn[maxn],low[maxn],num,q

UVA 315 Network

Description: A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N. No two places have the same number. The lines are bidirectional and always connect togethe