【poj1144】 Network
2016-08-18 16:13
369 查看
http://poj.org/problem?id=1144 (题目链接)
题意:求有向图的割点。
Solution
Tarjan求割点裸题。并不知道这道题的输入是什么意思,也不知道有什么意义= =,欺负我英语不好是吗。。。
代码:
题意:求有向图的割点。
Solution
Tarjan求割点裸题。并不知道这道题的输入是什么意思,也不知道有什么意义= =,欺负我英语不好是吗。。。
代码:
// poj1144 #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<set> #define MOD 1000000007 #define inf 2147483640 #define LL long long #define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); using namespace std; inline LL getint() { LL x=0,f=1;char ch=getchar(); while (ch>'9' || ch<'0') {if (ch=='-') f=-1;ch=getchar();} while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();} return x*f; } const int maxn=200; struct edge {int to,next;}e[maxn<<2]; int head[maxn],p[maxn],dfn[maxn],low[maxn],f[maxn]; int cnt,root,n,ind; void insert(int u,int v) { e[++cnt].to=v;e[cnt].next=head[u];head[u]=cnt; e[++cnt].to=u;e[cnt].next=head[v];head[v]=cnt; } void Tarjan(int u,int fa) { dfn[u]=low[u]=++ind; f[u]=1; for (int i=head[u];i;i=e[i].next) if (e[i].to!=fa) { if (!f[e[i].to]) { Tarjan(e[i].to,u); low[u]=min(low[u],low[e[i].to]); if (low[e[i].to]>=dfn[u] && u!=1) p[u]++; else if (u==1) root++; } else low[u]=min(low[u],dfn[e[i].to]); } } int main() { while (scanf("%d",&n)!=EOF && n) { for (int i=1;i<=n;i++) head[i]=low[i]=dfn[i]=f[i]=p[i]=0; int u,v;cnt=root=ind=0; while (scanf("%d",&u)!=EOF && u) while (getchar()!='\n') { scanf("%d",&v); insert(u,v); } Tarjan(1,0); int ans=0; if (root>1) ans++; for (int i=2;i<=n;i++) if (p[i]) ans++; printf("%d\n",ans); } return 0; }
相关文章推荐
- POJ 1144 - Network 用tarjan求无向图的割点
- poj1144 Network 双连通分量
- POJ-1144 Network 求割点
- poj1144-Network
- [poj1144]Network(求割点模板)
- POJ 1144 Network
- POJ 1144 / ZOJ 1311 : Network - 割点个数
- POJ 1144 Network 求割点个数
- POJ1144——Network
- POJ 1144 Network(Tarjan)
- POJ 1144 Network
- Network POJ - 1144
- POJ 1144 Network(Tarjan)
- POJ -1144 Network 求割点
- POJ 1144 Network(简单求无向图割顶数)
- POJ1144--Network
- Poj 1144 Network (割点)
- poj 1144 Network(Tarjan求割点)
- poj 1144 Network
- 【连通图|割点】POJ-1144 Network