有生以来做的第二道IOI题目居然也是96'的,又是一道比我还老的题目。

纯属复习或者说再学一遍Tarjan算法,本题的主要算法就是Tarjan+缩点,对于两个子问题的答案,根据解题:强连通缩点为拓扑图后,设入度为0点数为r,出度为0点数为c,则Task 1的答案就是r,这个很好理解;Task 2的答案是max(r,c),这个理解不能,但是我自己画了几个图都是这样的。如果真的比赛时遇到这种东西就要自己推理了…

仍然觉得Tarjan很抽象,就像很久以前觉得快排很抽象一样…我也许能够记下来标程,但是Don't know why才是最大的问题,出了个变式就只能呵呵。

能优化的地方就是,可以改写邻接表了… 数据给的就是邻接表我还转成邻接矩阵还要用循环找出个next,不过幸好数据里n<=100。

program vijos_p1595;
var d,low,scc,s,c,r:array[..] of integer;
visit,ins,mark_scc:array[..] of boolean;
map,map2:array[..,..] of integer;
i,j,n,t,top,r0,c0,count_scc:integer;
function max(a,b:integer):integer;
begin
if a>b then exit(a) else exit(b);
end; function min(a,b:integer):integer;
begin
if a<b then exit(a) else exit(b);
end; procedure tarjan(u:integer);
var v:integer;
begin
visit[u]:=true;
inc(t);d[u]:=t;low[u]:=t;
inc(top);s[top]:=u;ins[u]:=true;
for v:= to n do
if map[u,v]= then
begin
if not visit[v] then
begin
tarjan(v);
low[u]:=min(low[u],low[v]);
end
else
if ins[v] then
low[u]:=min(low[u],d[v]);
end;
if d[u]=low[u] then
repeat
v:=s[top];
scc[v]:=u;
ins[v]:=false;
dec(top);
until u=v;
end; begin
fillchar(map,sizeof(map),);
fillchar(map2,sizeof(map2),);
fillchar(visit,sizeof(visit),false);
fillchar(ins,sizeof(ins),false);
fillchar(mark_scc,sizeof(mark_scc),false);
readln(n);
for i:= to n do
begin
read(t);
while t<> do
begin
map[i,t]:=;
read(t);
end;
readln;
end;
for i:= to n do
if not visit[i] then tarjan(i);
for i:= to n do
for j:= to n do
if (map[i,j]=) and (scc[i]<>scc[j]) then map2[scc[i],scc[j]]:=;
for i:= to n do
for j:= to n do
if map2[i,j]= then
begin
inc(c[i]);
inc(r[j]);
end;
count_scc:=;
for i:= to n do
if mark_scc[scc[i]]=false then
begin
inc(count_scc);
mark_scc[scc[i]]:=true;
end;
for i:= to n do
if scc[i]=i then
begin
if c[i]= then inc(c0);
if r[i]= then inc(r0);
end;
writeln(r0);
if count_scc> then writeln(max(c0,r0)) else writeln();
end.

学校网络

测试数据 #0: Accepted, time = 0 ms, mem = 776 KiB, score = 8

测试数据 #1: Accepted, time = 0 ms, mem = 776 KiB, score = 10

测试数据 #2: Accepted, time = 0 ms, mem = 780 KiB, score = 10

测试数据 #3: Accepted, time = 0 ms, mem = 780 KiB, score = 8

测试数据 #4: Accepted, time = 0 ms, mem = 776 KiB, score = 8

测试数据 #5: Accepted, time = 0 ms, mem = 776 KiB, score = 8

测试数据 #6: Accepted, time = 0 ms, mem = 776 KiB, score = 8

测试数据 #7: Accepted, time = 0 ms, mem = 780 KiB, score = 10

测试数据 #8: Accepted, time = 0 ms, mem = 780 KiB, score = 10

测试数据 #9: Accepted, time = 0 ms, mem = 780 KiB, score = 10

测试数据 #10: Accepted, time = 11 ms, mem = 780 KiB, score = 10

[vijos P1595] 学校网络的更多相关文章

  1. 割点与桥,强连通分量,点双,边双[poj_1236]学校网络

    割点与桥 题目描述 给定一张无向图G(V,E),你需要找出所有的割点与桥. 输入 第一行给出两个正整数V,E. 接下来E行每行两个正整数x,y,表示有一条连接x,y的边. 输出 输出共2行,第一行输出 ...

  2. 【vijos】1769 网络的关键边(割边)

    https://vijos.org/p/1769 啊,割边写挫了害得我交了那么多发... 本题多想想就出来了.. 首先求出割边,显然关键边就在割边上. 求完割边后,我们先从一个点dfs,维护A的点数和 ...

  3. VijosP1595:学校网络(有向图变强连通图)

    描述 一些学校的校园网连接在一个计算机网络上.学校之间存在软件支援协议.每个学校都有它应支援的学校名单(学校a支援学校b,并不表示学校b一定支援学校a).当某校获得一个新软件时,无论是直接得到的还是从 ...

  4. POJ 1236 学校网络间的强连通

    题目大意: N个学校之间有单向的网络,每个学校得到一套软件后,可以通过单向网络向周边的学校传输.问题1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件.问题2:至少需要添加几条 ...

  5. poj1236学校网络——连通块

    题目:http://poj.org/problem?id=1236 通过传输文件的特点可以看出要先求强联通分量,缩点: 问题1:即缩点后入度为0的点,从它们开始传文件可以传给所有学校: 问题2:对于所 ...

  6. POJ1236学校网络——tarjan

    题目:http://poj.org/problem?id=1236 Tarjan+缩点.温习一下Tarjan的写法. 1.在缩点后的TAG中,有几个联通块等价于有几个入度为0的点! 2.把它们都联通相 ...

  7. 网络协议 13 - HTTPS 协议:加密路上无尽头

    系列文章传送门: 网络协议 1 - 概述 网络协议 2 - IP 是怎么来,又是怎么没的? 网络协议 3 - 从物理层到 MAC 层 网络协议 4 - 交换机与 VLAN:办公室太复杂,我要回学校 网 ...

  8. 网络协议 12 - HTTP 协议:常用而不简单

    系列文章传送门: 网络协议 1 - 概述 网络协议 2 - IP 是怎么来,又是怎么没的? 网络协议 3 - 从物理层到 MAC 层 网络协议 4 - 交换机与 VLAN:办公室太复杂,我要回学校 网 ...

  9. 网络协议 11 - Socket 编程(下):眼见为实耳听为虚

    系列文章传送门: 网络协议 1 - 概述 网络协议 2 - IP 是怎么来,又是怎么没的? 网络协议 3 - 从物理层到 MAC 层 网络协议 4 - 交换机与 VLAN:办公室太复杂,我要回学校 网 ...

随机推荐

  1. iOS开发之 Xcode 6 创建一个Empty Application

    参考链接http://jingyan.baidu.com/article/2a138328bd73f2074b134f6d.html Xcode 6 正式版如何创建一个Empty Applicatio ...

  2. git 命令行操作

    Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目 这里说一下在命令行对git进行操作 git init [在本地初始化一个git库] //当你的git服务器里面已经有文 ...

  3. 详解zabbix安装部署(Server端篇)

    原文:http://blog.chinaunix.net/uid-25266990-id-3380929.html Linux下常用的系统监控软件有Nagios.Cacti.Zabbix.Monit等 ...

  4. oracle查询一个数据库有几张表

    登录sys用户后通过user_tables表查看当前用户下表的张数.sql:conn / as sysdba;sql:select count(*) from user_tables ;解释:必须是登 ...

  5. Linux runlevel 运行级别

    runlevel可以认为是系统状态,形象一点,您可以认为runlevel有点象微软的windows操作系统中的Normal,safemode,和Command prompt only. Linux系统 ...

  6. 转:为什么C++中空类和空结构体大小为1?

    参考:http://www.spongeliu.com/260.html 为什么C++中空类和空结构体大小为1? On November 17, 2010, in C语言, 语言学习, by spon ...

  7. EI中国

    这里可以看到EI收录的所有的中国期刊:http://lib.sytu.edu.cn/files/zwwxx/2009-EI-china.htm

  8. 在Linux或者Unix下打开,每一行都会出多出^M这样的字符

    Windows上写好的文件,在Linux或者Unix下打开,每一行都会出多出^M这样的字符,这是因为Windows与*nix的换行符不同所致,我们看看文件格式有什么不同. 在Linux下查看文件格式: ...

  9. require 和 file_get_contents

    requirerequire_onceincludeinclude_oncecurlfile_get_contents---各种选择的比较 还有这么复杂的说法,怎么办? 在开发过程中发现,用requi ...

  10. Machine Learning - 第6周(Advice for Applying Machine Learning、Machine Learning System Design)

    In Week 6, you will be learning about systematically improving your learning algorithm. The videos f ...