比较笨啊,一直在想,到底问几次绝对能知道所有的关系呢?

后来看了题解才知道,问一次最少确定一对关系…………

这就好办le,n头牛有C(2,n)个关系

现在给出m条边,以确定的关系有多少呢?直接dfs啊……

……O(nm)

 type link=^node;
     node=record
       po:longint;
       next:link;
     end;
var w:array[..] of link;
    sum:array[..] of longint;
    v:array[..] of boolean;
    n,i,m,ans,x,y:longint; procedure add(x,y:longint);
  var p:link;
  begin
    new(p);
    p^.next:=w[x];
    p^.po:=y;
    w[x]:=p;
  end; procedure dfs(i:longint);
  var p:link;
      y:longint;
  begin
    p:=w[i];
    v[i]:=true;
    sum[i]:=;
    while p<>nil do
    begin
      y:=p^.po;
      if not v[y] then
      begin
        dfs(y);
        sum[i]:=sum[i]+sum[y];
      end;
      p:=p^.next;
    end;
  end; begin
  readln(n,m);
  for i:= to m do
  begin
    readln(x,y);
    add(x,y);
  end;
  for i:= to n do
  begin
    fillchar(v,sizeof(v),false);
    dfs(i);
    ans:=ans+sum[i]-;
  end;
  writeln(n*(n-) div -ans);
end.

poj3275的更多相关文章

  1. POJ3275 Ranking the Cows floyd的bitset优化

    POJ3275 Ranking the Cows #include <iostream> #include <cstdio> #include <bitset> u ...

  2. 离散数学-传递闭包(POJ3275)

    就是n的元素给定m个关系求他们之间的关系. eg.  ∵a>b and b>c ∴a>c emmmm 若要知道n个元素的绝对关系,则需知道C(n,2)个关系. 例题:POJ3275 ...

  3. POJ3275:Ranking the Cows(Bitset加速floyd求闭包传递)

    Each of Farmer John's N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ woul ...

  4. POJ-3275:Ranking the Cows(Floyd、bitset)

    Ranking the Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3301   Accepted: 1511 ...

  5. 【Bitset】重识

    ---------------------------------------------------------------------------- 一题题目: 一题题解: 这个题目哪来入门再好不 ...

  6. USACO 2007 “March Gold” Ranking the Cows

    题目链接:https://www.luogu.org/problemnew/show/P2881 题目链接:https://vjudge.net/problem/POJ-3275 题目大意 给定标号为 ...

  7. poj 3275 "Ranking the Cows"(DFS or Floyd+bitset<>)

    传送门 题意: 农场主 FJ 有 n 头奶牛,现在给你 m 对关系(x,y)表示奶牛x的产奶速率高于奶牛y: FJ 想按照奶牛的产奶速率由高到低排列这些奶牛,但是这 m 对关系可能不能精确确定这 n ...

随机推荐

  1. Spark小课堂Week5 Scala初探

    Spark小课堂Week5 Scala初探 Scala是java威力加强版. 对Java的改进 这里会结合StreamingContext.scala这个代码说明下对Java的改进方面. 方便测试方式 ...

  2. hadoop中遇到的问题。

    1.物理主机中无法访问管理界面,在虚拟主机中可以访问, 这跟防火墙有关系,重启一下防火墙,然后关闭,最后重启一下handoop,应该就可以了!!!!(hadoop首战顺利!!!!!(●'◡'●))

  3. LeetCode 解题报告--202Happy Number

    1 题目描述 Write an algorithm to determine if a number is "happy". A happy number is a number ...

  4. 扩展ServiceHost<T>类

    public class ServiceHost<T> : ServiceHost { public void EnableMetadataExchange(bool enableHttp ...

  5. 自学JAVA总结

    2.在定义常量的时候C语言中定义为const而JAVA中为final3.在JAVA声明成员变量的时候,使用static来定义.4.在JAVA中的boolean类型只包括true和false,但是在C中 ...

  6. Oracle的Import用法

    1. imp 命令介绍   imp 命令可以通过输入各种参数来控制导出方式:  imp keyword=value 或 keyword=(value1,value2,...,valueN) ,例如 i ...

  7. windows2003 64位 iis6.0 运行32位web应用程序

    适用于已安装.NET4.0的windows 2003 64位机器. 系统要求: windows 2003 sp1 步骤: 1. 打开命令行,转到目录: %systemdrive%\Inetpub\Ad ...

  8. .NET安装和配置Oracle数据访问组件(ODAC)

    Many ASP.NET applications access Oracle database for the data source. Oracle supports the .NET with ...

  9. mysql group by优化

    mysql> explain select actor.first_name,actor.last_name,count(*) from sakila.film_actor inner join ...

  10. EXTJS4.2 控件之Grid 行点击事件

    listeners: { 'itemclick': function (view, record, item, index, e) { //Ext.MessageBox.alert("标题& ...