zoukankan      html  css  js  c++  java
  • 【CF659E】New Reform(图的联通,环)

    分析转载自http://blog.csdn.net/yukizzz/article/details/51029628

    题意:

    给定n个点和m条双向边,将双向边改为单向边,问无法到达的顶点最少有多少个?

    分析:

    无法到达的话即入度为0。 
    DFS判断每一个连通块中是否存在环,如果存在环,就能保证环中每个点的入度都大于等于1。否则,有头有尾,头的入度为0。

     1 var head,vet,next,flag:array[1..200000]of longint;
     2     n,m,x,y,tmp,ans,tot,i:longint;
     3 
     4 procedure add(a,b:longint);
     5 begin
     6  inc(tot);
     7  next[tot]:=head[a];
     8  vet[tot]:=b;
     9  head[a]:=tot;
    10 end;
    11 
    12 procedure dfs(u,pre:longint);
    13 var e,v:longint;
    14 begin
    15  if flag[u]=1 then begin tmp:=0; exit; end;
    16  flag[u]:=1;
    17  e:=head[u];
    18  while e<>0 do
    19  begin
    20   v:=vet[e];
    21   if v<>pre then dfs(v,u);
    22   e:=next[e];
    23  end;
    24 end;
    25 
    26 begin
    27 // assign(input,'1.in'); reset(input);
    28  //assign(output,'1.out'); rewrite(output);
    29  readln(n,m);
    30  for i:=1 to m do
    31  begin
    32   read(x,y);
    33   add(x,y);
    34   add(y,x);
    35  end;
    36  for i:=1 to n do
    37   if flag[i]=0 then
    38   begin
    39    tmp:=1;
    40    dfs(i,0);
    41    ans:=ans+tmp;
    42   end;
    43  writeln(ans);
    44 // close(input);
    45  //close(output);
    46 end.
    View Code
  • 相关阅读:
    DNS服务器详解
    numpy学习
    test_pandas
    1.爬虫基本介绍
    数据分析介绍及软件使用 01
    3.解析库beautifulsoup
    jQuery UI vs EasyUI
    "file:///" file 协议
    Display:Block
    前端响应式设计中@media等的相关运用
  • 原文地址:https://www.cnblogs.com/myx12345/p/5540318.html
Copyright © 2011-2022 走看看