poj 1144 Network 关节点

简介:

Tarjan练手题,WA了两次,处理回边误把low[u]=min(low[u],dph[v]); 写成low[u]=min(low[u],low[v]);了,还要注意节点数小于2时输出0

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std;
int n,ans;
vector<int> node[101];
int dph[101],low[101],vis[101];
void dfs(int v,int d)
{
    dph[v]=low[v]=d;
    vis[v]=1;
    int u,ok=0;
    for(int i=0;i<node[v].size();i++)
    {
        u=node[v][i];
        if(vis[u])
        {
            low[v]=min(low[v],dph[u]);
        }
        else
        {
            dfs(u,d+1);
            if(low[u]>=dph[v])ok++;
            low[v]=min(low[v],low[u]);
        }
    }
    if(v!=1)ok++;
    if(ok>1)ans++;
}
int main()
{
    while(~scanf("%d",&n)&&n)
    {
        int v,u,i;
        for(i=1;i<=n;i++)node[i].clear();
        while(scanf("%d",&v)&&v)
        {
            while(getchar()!='\n')
            {
                scanf("%d",&u);
                node[v].push_back(u);
                node[u].push_back(v);
            }
        }
        ans=0;
        memset(vis,0,sizeof(vis));
        dfs(1,0);
        printf("%d\n",ans);
    }
}


目录
相关文章
|
6月前
POJ—2236 Wireless Network
POJ—2236 Wireless Network
|
6月前
Arctic Network( POJ - 2349)
Arctic Network( POJ - 2349)
[POJ 1236] Network of Schools | Tarjan缩点
Description A number of schools are connected to a computer network. Agreements have been developed among those schools: each school maintains a list of schools to which it distributes software (the “receiving schools”).
136 0
[POJ 1236] Network of Schools | Tarjan缩点
|
算法 数据建模
【POJ 1236 Network of Schools】强联通分量问题 Tarjan算法,缩点
题目链接:http://poj.org/problem?id=1236 题意:给定一个表示n所学校网络连通关系的有向图。现要通过网络分发软件,规则是:若顶点u,v存在通路,发给u,则v可以通过网络从u接收到。
1185 0
POJ-1004-Finanical Management
Description Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough.
891 0