无向图求割点 UVA 315 Network

输入数据处理正确其余的就是套强联通的模板了

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <cstring>
using namespace std;
#define INF 0xfffffff
#define maxn 106
#define min(a,b) (a<b?a:b)
/*无向图求桥和割点*/
vector<int> G[maxn];
int Father[maxn], time, dfn[maxn], low[maxn], n;
bool cut[maxn];

void init()
{
    memset(Father, 0, sizeof(Father));
    memset(low, 0, sizeof(low));
    memset(dfn, 0, sizeof(dfn));
    memset(cut, false, sizeof(cut));
    time = 1;
    for(int i=1; i<=n; i++)
        G[i].clear();
}
void tarjan(int u,int father)
{
    Father[u] = father;
    low[u] = dfn[u] = time ++;
    int len = G[u].size(), i, v;

    for(i=0; i<len; i++)
    {
        v = G[u][i];
        if(!low[v])
        {
            tarjan(v, u);
            low[u] = min(low[u], low[v]);
        }
        else if(v != father)
        {
            low[u] = min(low[u], dfn[v]);
        }
    }
}
void solve()
{
    int i, RootSons = 0, v, num = 0;
    tarjan(1, 0);
    for(i=2; i<=n; i++)
    {
        v = Father[i];
        if(v == 1)
            RootSons ++;
        else if(dfn[v] <= low[i])
            cut[v] = true;

    }
    if(RootSons > 1)
        cut[1] = true;
    for(i=1; i<=n; i++)
    {
        if(cut[i])
            num ++;
    }
    printf("%d\n", num);

}

int main()
{
    int a, b;
    char ch;
    while(scanf("%d",&n), n)
    {
        init();
        while( scanf("%d",&a), a)
        {
            while( scanf("%d%c",&b,&ch) )
            {
                G[a].push_back(b);
                G[b].push_back(a);
                if(ch == ‘\n‘)
                    break;
            }
        }

        solve();
    }
    return 0;
}
时间: 2024-08-25 13:39:24

无向图求割点 UVA 315 Network的相关文章

无向图求割点 UVA 315

***割点概念:去掉一个点后图不连通,改点就为割点 割点满足的条件: 一个顶点u是割点,当且仅当满足(1)或(2) (1)一个顶点u是割点,当且仅当满足(1)或(2). (2) u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的父亲),使得 dfn(u)<=low(v). 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=122091#problem/B*** #include<cstdio>

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(连通图求割点)

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

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

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

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

B - Network---UVA 315(无向图求割点)

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 places

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

poj 1144 Network 无向图求割点

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

(连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)

链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=251 http://poj.org/problem?id=1144 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82833#problem/B 代码: #include<cstdio> #include<