[vijos P1023] Victoria的舞会3

这… 本来想学习一下Tarjan算法的,没想到码都码好了发现这题不是求强连通分量而是简单的连通分量…图论基础都还给老师了啊啊啊!最后深搜通通解决!

v标记是否被访问过,scc标记每个的祖先(本来想写Tarjan的才弄出这么奇葩个数组名字),w用于最后的统计。

[vijos P1023] Victoria的舞会3
program vijos_p1023;
var map:array[0..210,0..210] of longint;
    v,w:array[0..210] of boolean;
    n,m,t,i,ans,top:longint;
    low,s,scc:array[0..210] of longint;

procedure search(u,a:integer);
var i:integer;
begin
  v[u]:=true;
  for i:=1 to n do
    if (map[u,i]<>0) and (v[i]=false) then
      begin
        scc[i]:=a;
        search(i,a);
      end;
end;

begin
  fillchar(v,sizeof(v),false);
  fillchar(w,sizeof(w),false);
  fillchar(map,sizeof(map),0);
  readln(n);
  for i:=1 to n do
    begin
      read(t);
      while t<>0 do
        begin
          map[i,t]:=1;
          read(t);
        end;
    end;
  for i:=1 to n do
    if v[i]=false then
      begin
        scc[i]:=i;
        search(i,i);
      end;
  for i:=1 to n do
    begin
      if w[scc[i]]=false then
        begin
          w[scc[i]]:=true;
          inc(ans);
        end;
    end;
  writeln(ans);
end.
Victoria的舞会3

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

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

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

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

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

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

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

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

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

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

Accepted, time = 0 ms, mem = 916 KiB, score = 100

0ms秒杀刷正确率什么的还是挺爽的。

[vijos P1023] Victoria的舞会3

上一篇:相关性分析作图(热图+数值)/(直方图+数值)R语言


下一篇:使用axios模拟表单提交