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

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

这就好办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. 代码分享:php判断数组是否有序

    发布:脚本学堂/PHP编程  编辑:JB02   2013-12-17 14:59:02  [大 中 小] 转自:http://www.jbxue.com/article/14723.html如何判断 ...

  2. ECSHOP如何解决购物车中商品自动消失问题

    最近有客户反映关于ECShop购物车的问题:需要加入多个商品到购物车时,发现之前加入到购物车的商品都自动消失了,只有最后一次加入购物车的商品在里面.那么,这是什么原因呢? 因为ECShop的SESSI ...

  3. 快速搭建Web环境 Angularjs + Express3 + Bootstrap3

    快速搭建Web环境 Angularjs + Express3 + Bootstrap3 AngularJS体验式编程系列文章, 将介绍如何用angularjs构建一个强大的web前端系统.angula ...

  4. .net mvc 防止 xss 与 CSRF

    CSRF(Cross-site request forgery跨站请求伪造,也被称成为“one click attack”或者session riding,通常缩写为CSRF或者XSRF,是一种对网站 ...

  5. liger grid loadData

    function fn_Search() { var beginDt = $("#txtBegin").val(); var endDt = $("#txtEnd&quo ...

  6. RichTextBox控件-主要用于输入输出编辑文本信息

    1.在RichTextBox控件中添加超链接文字 private void btn_Add_Click(object sender, EventArgs e) { rtbox_HyperLink.Ap ...

  7. oracle 表空间、用户名 相关语句

    一.oracle查询表空间文件所在路径 select * from dba_data_files t  where t.tablespace_name='FLW' 二.计算出表空间各相关数据 SELE ...

  8. mac系统在控制台中ping网址提示不能解析host

    更换dns就好了 系统偏好设置——网络——dns 换成 8.8.8.8 114.114.114.114 也可以参考v2ex的dns http://www.guomii.com/posts/5315

  9. UITableView自定义单元格

    随手笔记: RootViewController代码 #import "RootViewController.h" #import "AddressContact.h&q ...

  10. MS SQL Server时间常用函数

    SQLServer时间日期函数详解,SQLServer,时间日期, 1.      当前系统日期.时间 select getdate() 2. dateadd      在向指定日期加上一段时间的基础 ...