做完Victoria的舞会3,挑了vijos里强连通分量里面难度值最低的题目,也就是这道。先把第一小问做了,纯Tarjan,只是我学的时候的标程是用邻接表的,这题数据小于是用了邻接矩阵,两者之间的切换花了点时间,我天真地以为i<j等价于i的时间戳小于j的了,呵呵,那时候天真地连d数组都没写…

第二问看别人写了是用n次dfs?我多念了几遍题这**不就是明星奶牛么…感觉这两题基本都没什么差别。放假前老师给明星奶牛的评价是,做了这题图论基本复习了一遍…好吧,是啊,我把书翻出来,敲了一遍拓扑排序…

写完总觉得有点虚,觉得第二问的解法还有漏洞,我对于-1的唯一判断就是拓扑的时候有大于一个的出入度都为零的定点出现,不太清楚这个对不对…这题是不是改一改就能过明星奶牛了?

P.S. 好久没有码100行+的程序了,调试起来非常的虚。是我见识太狭隘还是代码风格太简洁还是做的都是水题?

P.S.2 题目描述里引用了《爱因为在心中》的歌词,挺喜欢这首歌的…~

P.S.3 不要理程序里的那个prim,一脑残忘记拓扑排序叫什么了,不是最小生成树…

program vijos_p1626;
type ty=record
x,y:integer;
end;
var map,map2:array[..,..] of word;
scc,low,s,w,d:array[..] of integer;
v,sc:array[..] of boolean;
jl:array[..] of ty;
n,m,i,j,x,y,top,ans,t,ans2_,ans_t:integer;
procedure tarjan(u:integer);
var i:integer;
begin
v[u]:=true;
inc(top);s[top]:=u;sc[u]:=true;
inc(t);d[u]:=t;low[u]:=t;
for i:= to n do
if map[u,i]<> then
begin
if v[i]=false then
begin
tarjan(i);
if low[i]<low[u] then low[u]:=low[i];
end
else
if (sc[i]=true) and (d[i]<low[u]) then low[u]:=d[i]; {!!!}
end;
if d[u]=low[u] then
repeat
i:=s[top];
scc[i]:=u;
sc[s[top]]:=false;
dec(top);
until i=u;
end; procedure prim;
var r,c:array[..] of integer;
stack:array[..] of integer;
min,min_loc,i,j,top,now:integer;
begin
fillchar(r,sizeof(r),);
fillchar(c,sizeof(c),);
fillchar(stack,sizeof(stack),);
for i:= to n do
for j:= to n do
if (map2[i,j]=) and (i<>j) then
begin
inc(r[j]);
inc(c[i]);
end;
top:=;
for i:= to n do
if (r[i]=) and (scc[i]=i) then
begin
inc(top);
stack[top]:=i;
if c[i]= then
begin
writeln('-1');
halt;
end;
end;
while top> do
begin
now:=stack[top];dec(top);
if (c[now]=) and (top<>) then
begin
writeln('-1');
halt;
end;
for i:= to n do
if map2[now,i]= then
begin
dec(r[i]);
if r[i]= then
begin
inc(top);
stack[top]:=i;
end;
end;
if top= then
begin
ans2_:=stack[];
break;
end;
end;
end; begin
readln(n,m);
for i:= to m do
begin
readln(jl[i].x,jl[i].y);
map[jl[i].x,jl[i].y]:=;
end;
fillchar(v,sizeof(v),false);
fillchar(w,sizeof(w),);
for i:= to n do
if v[i]=false then tarjan(i);
for i:= to n do
begin
inc(w[scc[i]]);
if w[scc[i]]= then inc(ans);
if w[scc[i]]= then inc(ans_T);
end;
writeln(ans);
if (ans=) then
begin
writeln('-1');
halt;
end;
if (ans=) and (ans_t=) then ans2_:=scc[]
else
begin
for i:= to m do
map2[scc[jl[i].x],scc[jl[i].y]]:=; {xiao xin huan}
ans2_:=-;
prim;
end;
for i:= to n do
if scc[i]=ans2_ then write(i,' ');
end.

爱在心中

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

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

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

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

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

测试数据 #5: Accepted, time = 15 ms, mem = 4704 KiB, score = 10

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

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

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

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

Accepted, time = 30 ms, mem = 4704 KiB, score = 100

[vijos P1626] 爱在心中的更多相关文章

  1. Vijos——T1626 爱在心中

    https://vijos.org/p/1626 描述 “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸,世界就像迷宫,却又让我们此刻相逢Our H ...

  2. 【codevs2822】爱在心中 tarjan 缩点+理解

    [codevs2822]爱在心中 2014年1月26日5580 题目描述 Description “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸, ...

  3. 【CodeVS 2822】爱在心中

    “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸,世界就像迷宫,却又让我们此刻相逢Our Home.” 在爱的国度里有N个人,在他们的心中都有着一个 ...

  4. codevs 2822 爱在心中

    codevs 2822 爱在心中  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description “每个人都拥有一个梦,即使彼此不相同, ...

  5. codevs2822 爱在心中

      2822 爱在心中 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无 ...

  6. 【codevs2822】爱在心中

    题目描述 Description “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸,世界就像迷宫,却又让我们此刻相逢Our Home.” 在爱的国度 ...

  7. VijosP1626:爱在心中

    描述 “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸,世界就像迷宫,却又让我们此刻相逢Our Home.” 在爱的国度里有N个人,在他们的心中都有 ...

  8. 爱在心中(codevs 2822)

    题目描述 Description “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸,世界就像迷宫,却又让我们此刻相逢Our Home.” 在爱的国度 ...

  9. codevs——2822 爱在心中

    2822 爱在心中  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description “每个人都拥有一个梦,即使彼此不相 ...

随机推荐

  1. JAVA学习提高之----安装多个JDK版本的问题

    我的机器上最开始安装的是jdk1.6,后来因为工作需要又安装了jdk1.4.但是,环境变量我并未更改,还是指向jdk1.6的路径的.可是,在cmd窗口输入 Java -version 却得到是1.4. ...

  2. select动态增加option

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  3. python 远程执行命令、上传、下载举例

    使用python中的 paramiko 实现远程操作,需要安装 paramiko 模块. # vi pssh.py #!/usr/bin/python #coding=utf-8 ''' Create ...

  4. 转!!!Mybatis实现数据的增删改查(CRUD)

    什么是 MyBatis? MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索.MyBat ...

  5. html中盒子模型立体结构图

    边框(border),位于盒子的第一层..元素内容(content).内边距(padding),两者同位于第二层..背景图(background-image),位于第三层..背景色(backgroun ...

  6. 2016最全的web前端面试题及答案整理

    面试web前端开发,不管是笔试还是面试,都会涉及到各种专业技术问题,今天小编整理了一些常见的web前端面试题及答案,希望对大家有所帮助. 1.常用那几种浏览器测试?有哪些内核(Layout Engin ...

  7. commonJS — 数组操作(for Array)

    for Array github: https://github.com/laixiangran/commonJS/blob/master/src/forArray.js 代码 /** * Creat ...

  8. root的方法大体上有以下三种

    root的方法大体上有以下三种一.手机软件安卓版直接root.这种方法不需要电脑的支持,也很安全.安卓版软件有:kingroot,360一键root,一键root大师,Towelroot,支持云roo ...

  9. 倒计时原生js

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Azure 云平台用 SQOOP 将 SQL server 2012 数据表导入 HIVE / HBASE

    My name is Farooq and I am with HDinsight support team here at Microsoft. In this blog I will try to ...