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

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

这就好办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. 伪元素content的应用

    日常开发中,我们常用:before,:after来实现一些效果,比如 – 边框 – 图标 此时的content中只是为了伪元素能渲染出来而声明 1 2 3 div:before{ content: & ...

  2. lnmp全面优化集合nginx+mysql+php

    lnmp的全名是linux+nginx+mysql+php,既然是全面优化那我们就从linux系统的选择入手.debian系统可以算是 linux各分支中做的比较突出的一类,连谷歌都抛弃linux订制 ...

  3. DrawWindowFrame

    extern void DrawWindowFrame(HWND hWnd)//画窗口边框 { RECT rc; HWND DeskHwnd = ::GetDesktopWindow(); //取得桌 ...

  4. u3d 2d序列动画代码

    using UnityEngine; using System.Collections; public class AniSprite : MonoBehaviour { private float ...

  5. SQLite3中自增主键

    SQLite清空表并将自增列归零 SQL标准中有TRUNCATE TABLE语句,用来清空表的所有内容. 但SQLite不支持这个语句.在SQLite中直接使用 DELETE FROM TableNa ...

  6. 云主机上搭建squid3代理服务器

    目录 目录 具体流程 修改配置文件 问题 维基整理 代理服务器 Squid (软件) SOCKS SOCKS代理 参考:http://raysmond.com/node/79 具体流程 在服务器上安装 ...

  7. Eclipse 中隐藏的 5 个非常有用的功能

    Eclipse就是一头野兽.它也是一套设备,神秘但更具威力.有些人称它为一个持续变形机.另一些人则称它是一个变异体.不错,它很庞大,需要花费多年才能掌握.而在你好不容易掌握之后,你的老板出现了然后告诉 ...

  8. fineui框架

    http://fineui.com/demo/#/demo/layout/fit.aspx 虽然比较丑陋,但功能实用 此框架比较简单, 框架的作用你懂的,重点是要有帮助文档, 进阶型的容易上手的帮助文 ...

  9. Java中的break与continue区别

    break跳出当前循环执行循环下面的程序, 如果break出现在嵌套循环的内层循环, 则break语句只会跳出当前层的循环; 当程序执行到continue时时, 则跳过本次循环程序重新回到循环开始继续 ...

  10. PHP中CURL方法curl_setopt()函数的一些参数 (转)

    bool curl_setopt (int ch, string option, mixed value) curl_setopt()函数将为一个CURL会话设置选项.option参数是你想要的设置, ...