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

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

这就好办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. 让Ecshop网店系统用户自动登陆

    让Ecshop网店系统用户户自动登陆,打开ecshop includes/init.php文件,可以发现Ecshop系统判断用户的SESSION不存在的时候会去读取存储在COOKIES里面的值.如下代 ...

  2. 学习VirtualEnv和Nginx+uwsgi用于django项目部署

    以下叙述中用到的操作系统:Linux CentOS 6.X. 最近几天了解一下VirtualEnv,Apache+Daemon mode,Nginx+uwsgi的概念,并且在项目中实验性部署了一下(目 ...

  3. 十七、mysql 分区之 锁问题

    1.演示一个表锁,基于myisam CMD 1 CMD2 create table e1 (id int ,name char(20)); lock table e1 read; [select|in ...

  4. 【BZOJ 1031】[JSOI2007]字符加密Cipher

    Description 喜欢钻研问题的JS 同学,最近又迷上了对加密方法的思考.一天,他突然想出了一种他认为是终极的加密办法:把需要加密的信息排成一圈,显然,它们有很多种不同的读法.例如下图,可以读作 ...

  5. python学习笔记24(路径与文件 (os.path包, glob包))

    os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法. >>> import os.path >>> path = '/home/ ...

  6. 认识FiddlerScript

    FiddlerScript 是Fiddler 的一项非常强大的功能,它允许你增强Fiddler UI,添加新的特性,修改请求与响应内容等等... 1.编写FiddlerScript FiddlerSc ...

  7. 一个简单的C#加密解密类

    //DES默认密钥向量 private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; /// < ...

  8. MySQL在windows和linux下的表名大小写问题

    MySQL在windows下是不区分大小写的,将script文件导入MySQL后表名也会自动转化为小写,结果再想要将数据库导出放到linux服务 器中使用时就出错了.因为在linux下表名区分大小写而 ...

  9. 【BZOJ 1069】 凸包+旋转卡壳

    1069: [SCOI2007]最大土地面积 Description 在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. Input 第 ...

  10. 网上图书商城项目学习笔记-014购物车模块页面javascrip

    一.流程分析 二.代码 1.view层 (1)list.jsp <%@ page language="java" import="java.util.*" ...