有生以来做的第二道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. hdu 4521 小明系列问题——小明序列(线段树 or DP)

    题目链接:hdu 4521 本是 dp 的变形,却能用线段树,感觉好强大. 由于 n 有 10^5,用普通的 dp,算法时间复杂度为 O(n2),肯定会超时.所以用线段树进行优化.线段树维护的是区间内 ...

  2. 遮罩、警告框/弹框 - EasyUI

    1.遮罩 1.1. $.messager.progress //开启遮罩 $.messager.progress({}); 或 $.messager.progress({ title: 'Please ...

  3. poj2975(nim游戏取法)

    求处于必胜状态有多少种走法. if( (g[i]^ans) <= g[i]) num++; //这步判断很巧妙 // // main.cpp // poj2975 // // Created b ...

  4. CentOS查看内核版本,位数,版本号 (zhuan)

    http://blog.csdn.net/painsonline/article/details/7668824 ******************************************* ...

  5. linux runlevel

    Linux系统有7个运行级别(runlevel)运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆运行级别2:多 ...

  6. Hbase之插入数据

    /** * Created by similarface on 16/8/17. */ import org.apache.hadoop.conf.Configuration; import org. ...

  7. html list <==> unformatted list

    两者的区别很大不得不擦呢,任何两个东西的差别都很大,不得混淆.---一个有ul/ol的选择,一个没有

  8. Linux命令行下编译Android NDK的示例代码

    这几天琢磨写一个Android的Runtime用来加速HTML5 Canvas,让GameBuilder+CanTK 不但开发速度快,运行速度也能接近原生应用.所以花了点时间研究 Android ND ...

  9. js上下滚屏效果,代码通过测试

    这是html代码 <div class="box"> <div class="bcon"> <h1><b>领号实 ...

  10. WCF技术剖析之二:再谈IIS与ASP.NET管道

    原文地址:http://www.cnblogs.com/artech/archive/2009/06/20/1507165.html 在2007年9月份,我曾经写了三篇详细介绍IIS架构和ASP.NE ...