POJ 1236 Network of Schools
来源:互联网 发布:mac上的解压缩软件 编辑:程序博客网 时间:2024/05/21 22:29
强连通分量
问题一,缩点后,求出所有入度为0的点的个数;
问题二,缩点后,求出入度为0的点的个数和出度为0的点的个数中的最大值
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>using namespace std;vector<int> g[120];int tg[120];int dfn[120];int low[120];bool ins[120];int s[120],ls;int incnt[120],outcnt[120];int key;int tag;int min(int a,int b){ return a>b?b:a;}void tarjan(int u){ int v,i; dfn[u]=key; low[u]=key; key++; ins[u]=true; s[ls]=u; ls++; for (i=0; i<g[u].size(); i++) { v=g[u][i]; if (dfn[v] == -1) { tarjan(v); low[u]=min(low[u],low[v]); } else if (dfn[v] != -1 && ins[v] == true) { low[u]=min(low[u],dfn[v]); } } if (dfn[u] == low[u]) { do { v=s[ls-1]; ls--; ins[v]=false; tg[v]=tag; }while (v != u); tag++; }}int main(){ int n,i,j,t1,res1,res2; scanf("%d",&n); for (i=1; i<=n; i++) { while (1) { scanf("%d",&t1); if (t1 == 0) break; g[i].push_back(t1); } } memset(dfn,-1,sizeof(dfn)); memset(ins,false,sizeof(ins)); key=1; tag=1; ls=0; for (i=1; i<=n; i++) { if (dfn[i] == -1) tarjan(i); } tag--; memset(incnt,0,sizeof(incnt)); memset(outcnt,0,sizeof(outcnt)); for (i=1; i<=n; i++) { for (j=0; j<g[i].size(); j++) { if (tg[i] == tg[g[i][j]]) continue; incnt[tg[g[i][j]]]++; outcnt[tg[i]]++; } } res1=0; res2=0; for (i=1; i<=tag; i++) { // printf("%d %d\n",incnt[i],outcnt[i]); if (incnt[i] == 0) res1++; if (outcnt[i] == 0) res2++; } printf("%d\n",res1); if (tag == 1) { printf("0\n"); } else { printf("%d\n",res1>res2?res1:res2); }}
- POJ 1236 Network of Schools
- POJ 1236 Network of Schools
- poj 1236 Network of Schools
- POJ 1236 Network of Schools
- POJ 1236 Network of Schools
- poj 1236 Network of Schools
- poj 1236 Network of Schools
- POJ 1236 Network of Schools
- POJ-1236-Network of Schools
- POJ 1236 Network of Schools
- POJ 1236 Network of Schools
- poj 1236 Network of Schools
- poj 1236 Network of Schools
- POJ-1236-Network of Schools
- POJ 1236 Network of Schools
- poj 1236 Network of Schools
- Network of Schools (POJ 1236)
- POJ 1236:Network of Schools
- 50个jQuery代码段帮你成为更出色的JS开发者
- 导入svn项目时eclipse崩溃
- Struts2的OGNL标签详解
- i OS UT coverage
- struct关键字---C语言深度剖析读书笔记9
- POJ 1236 Network of Schools
- Kinect SDK1.7 迎来重大更新
- (代码4)简单视频控制
- C#对EXCEL文件操作
- winRT 图片验证码生成
- Apache Common fileUpload API 详解
- js---js的concat函数、join 、slice函数及二维数组的定义方式
- Android关于OnTouch 和OnClick同时调用冲突的解决方案
- UML类图