COGS 908 校园网
/*
Tarjan缩点之后
强联通分量建图 统计每个强联通分量的出入度
第一问就是入度为0的 强联通分量的个数
第二问 为了高效的使每个强联通分量都有出入度
要把出度为零的强联通分量连到入度为零的点上 这样得到的边数是最少的
ans2并不是桥的数目 这样不是最少.....
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 110
#define maxm 10010
using namespace std;
int n,num,g[maxn][maxn],head[maxn],sum,tot,belong[maxn];
int dfn[maxn],low[maxn],stack[maxm],top,f[maxn],ans1,ans2;
int chu[maxn],ru[maxn];
struct node
{
int u,v,pre;
}e[maxm];
struct Node
{
int c[maxn];
int size;
}ans[maxn];
int init()
{
int x=;char s;bool f=;s=getchar();
while(s<''||s>''){if(s=='-')f=;s=getchar();}
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
if(f)return -x;return x;
}
void Add(int from,int to)
{
num++;
e[num].u=from;
e[num].v=to;
e[num].pre=head[from];
head[from]=num;
}
void Tarjan(int s)
{
dfn[s]=low[s]=++tot;
stack[++top]=s;
f[s]=;
for(int i=head[s];i;i=e[i].pre)
{
if(!dfn[e[i].v])
{
Tarjan(e[i].v);
low[s]=min(low[s],low[e[i].v]);
}
else if(f[e[i].v])
low[s]=min(low[s],dfn[e[i].v]);
}
if(dfn[s]==low[s])
{
sum++;
while(s!=stack[top])
{
ans[sum].size++;
belong[stack[top]]=sum;
ans[sum].c[ans[sum].size]=stack[top];
f[stack[top]]=;
top--;
}
ans[sum].size++;
belong[stack[top]]=sum;
ans[sum].c[ans[sum].size]=stack[top];
f[stack[top]]=;
top--;
}
}
int main()
{
//freopen("schlnet.in","r",stdin);
//freopen("schlnet.out","w",stdout);
n=init();
int x;
for(int i=;i<=n;i++)
while()
{
x=init();
if(x==)break;
Add(i,x);
}
for(int i=;i<=n;i++)
if(!dfn[i])
Tarjan(i);
for(int i=;i<=n;i++)
{
for(int j=head[i];j;j=e[j].pre)
{
if(belong[i]!=belong[e[j].v])
{
if(g[belong[i]][belong[e[j].v]]==)
{
chu[belong[i]]++;
ru[belong[e[j].v]]++;
}
g[belong[i]][belong[e[j].v]]=;
}
}
}
for(int i=;i<=sum;i++)
{
if(ru[i]==)ans1++;
if(chu[i]==)ans2++;
}
if(sum==)
{
printf("1\n0\n");
return ;
}
printf("%d\n%d\n",ans1,max(ans1,ans2));
return ;
}
COGS 908 校园网的更多相关文章
- cogs——908. 校园网
908. 校园网 ★★ 输入文件:schlnet.in 输出文件:schlnet.out 简单对比 时间限制:1 s 内存限制:128 MB USACO/schlnet(译 by Fe ...
- tarjan算法+缩点--cojs 908. 校园网
cojs 908. 校园网 ★★ 输入文件:schlnet.in 输出文件:schlnet.out 简单对比时间限制:1 s 内存限制:128 MB USACO/schlnet(译 b ...
- COGS——C 908. 校园网 || 洛谷——P 2746 [USACO5.3]校园网Network of Schools
http://www.cogs.pro/cogs/problem/problem.php?pid=908 || https://www.luogu.org/problem/show?pid=27 ...
- cogs908. 校园网
908. 校园网 ★★ 输入文件:schlnet.in 输出文件:schlnet.out 简单对比时间限制:1 s 内存限制:128 MB USACO/schlnet(译 by Fel ...
- 锐捷linux客户端常用命令(主要用来连接校园网或公司局域网)
锐捷访问校园网,.sh脚本文件rjsu*.sh-u 用户名-P 密码-S 参数1保存密码参数0不保存密码 其实: 直接使用md5认证方式输入用户名密码并且配置好ip之后,重新打开网卡即可有一定 ...
- 配置VMware虚拟机用绕过校园网达到无线上网配置方法
因为平时要用到Vmware这样的工具上虚拟机上网, 但是本人是学生狗,学生狗在学校就要面对大学毒瘤软件--锐捷,而锐捷是不允许有虚拟网卡的存在的,所以上网只能用wifi上.之前试了很久,反正是怎么开都 ...
- [机器学习] Ubuntu 软件源更新(校园网)以及问题总结
最近在折腾Linux,在校园网下怎么能够很好的获取软件很是让我头疼啊~~~ 总结一下吧!!! 首先是校园网的源地址: 清华大学:https://mirrors.tuna.tsinghua.edu.cn ...
- 绕过校园网的共享限制 win10搭建VPN服务器实现--从入门到放弃
一.开篇立论= =.. 上次说到博主在电脑上搭建了代理服务器来绕过天翼客户端的共享限制,然而经过实际测试还不够完美,所以本着生命不息,折腾不止的精神,我又开始研究搭建vpn服务器= =... (上次的 ...
- 【COGS 254】【POI 2001】交通网络图
http://www.cogs.top/cogs/problem/problem.php?pid=254 dist[i]表示能最早到达i点的时间.这样就可以用最短路模型来转移了. #include&l ...
随机推荐
- JS动画理论
动画(Animation) 动画意味着随着时间而变化,尤其指视觉上的变化,包括位置.形态等的变化.运动基本上表现为物体随时间,发生位置上的变化:形态基本表现为大小.颜色.透明度.形状等随时间的变化. ...
- iscc2016-basic-明察秋毫
查看源代码,找到maybe not flag : Jr1p0zr2VfPp 移位密码,注意判断字母大小写,并且数字无变化 s = "Jr1p0zr2VfPp" p = list(s ...
- 隐藏 response headers
1.response headers 为何物 从上图看到..这 透漏出服务器端 1.操作系统版本, IIS版本.开发语言 .以及.net framework 版本 虽然现在IIS 可以挂php .甚至 ...
- hdfs 常用命令
(2)bin/hdfs dfs -mkdir -p /home/雨渐渐 (3)scp /media/root/DCE28B65E28B432E/download/第2周/ChinaHadoop第二讲\ ...
- 开源java
http://code.google.com/p/nullpomino/source/checkout http://www.open-open.com/open254058.htm http://w ...
- 在 C++Builder 工程里使用 Visual C++ DLL(3个工具) good
译者序: 第一次读这篇文章是在 2001 年 10 月,帮我解决了一点小问题.本来不好意思翻译,因为英语水平实在太差.最近发现不少网友在问在 C++Builder 的工程里调用 Visual C++ ...
- 连接各种数据库神器———DbVisualizer
作为开发人员,经常会遇到在不同的数据库环境中进行开发或者调试,所以针对每种数据库都要安装对应的客户端,不但要占用硬盘控件而且还要经常切换,无可厚非这是一项头疼并且麻烦的事情.有了DbVisualize ...
- Lowest Common Ancestor in Binary Tree
The problem: Given node P and node Q in a binary tree T. Find out the lowest common ancestor of the ...
- POJ2442 Sequence
题目链接. #include <iostream> #include <cstdio> #include <cstring> #include <cstdli ...
- 搜索(DLX): POJ 3074 3076 Sudoku
POJ 3074 : Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller ...