| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 10855 | Accepted: 5020 |
Description
Input
Output
Sample Input
5 5 1 2 3 4 0 6 2 1 3 5 4 6 2 0 0
Sample Output
1 2
Hint
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
#define CASE(T) for(scanf("%d",&T);T--;)
typedef long long LL;
const int maxn = 100 + 5;
const int maxm = 10000 + 5;
int N, ans;
bool Map[maxn][maxn];
struct Edge
{
int to, next;
} edge[maxm];
int head[maxn], tot;
int Low[maxn], DFN[maxn];
int Index;
bool cut[maxn];
void AddEdge(int u, int v)
{
edge[tot].to = v, edge[tot].next = head[u];
head[u] = tot++;
}
void Tarjan(int u, int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
int son = 0;
for(int i = head[u]; ~i; i = edge[i].next)
{
v = edge[i].to;
if(v == pre) continue;
if(!DFN[v])
{
son++;
Tarjan(v, u);
if(Low[u] > Low[v]) Low[u] = Low[v];
if(u != pre && Low[v] >= DFN[u])
{
if(!cut[u]) ans++;
cut[u] = true;
}
}
else if(Low[u] > DFN[v]) Low[u] = DFN[v];
}
if(u == pre && son > 1)
{
if(!cut[u]) ans++;
cut[u] = true;
}
}
void init()
{
memset(Map, false, sizeof(Map));
ans = 0;
memset(head, -1, sizeof(head));
tot = 0;
}
stringstream BUF;
string buf;
void Read_Graph()
{
int a, b;
while(1)
{
scanf("%d", &a);
if(a == 0) break;
getline(cin, buf);
BUF.clear();
BUF << buf;
while(BUF >> b)
{
Map[a][b] = Map[b][a] = true;
}
}
for(int i = 1; i <= N; i++)
{
for(int j = 1; j < i; j++)
{
if(Map[i][j])
{
AddEdge(i, j), AddEdge(j, i);
}
}
}
}
void Solve()
{
memset(DFN, 0, sizeof(DFN));
memset(cut, false, sizeof(cut));
Index = 0;
for(int i = 1; i <= N; i++) if(!DFN[i])
{
Tarjan(i, i);
}
printf("%d\n", ans);
}
int main()
{
// FIN;
while(~scanf("%d", &N), N)
{
init();
Read_Graph();
Solve();
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1144 & Uva 315 Network 【求割点数目】
原文地址:http://blog.csdn.net/acmore_xiong/article/details/48025893