poj3275
比较笨啊,一直在想,到底问几次绝对能知道所有的关系呢?
后来看了题解才知道,问一次最少确定一对关系…………
这就好办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的更多相关文章
- POJ3275 Ranking the Cows floyd的bitset优化
POJ3275 Ranking the Cows #include <iostream> #include <cstdio> #include <bitset> u ...
- 离散数学-传递闭包(POJ3275)
就是n的元素给定m个关系求他们之间的关系. eg. ∵a>b and b>c ∴a>c emmmm 若要知道n个元素的绝对关系,则需知道C(n,2)个关系. 例题:POJ3275 ...
- 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 ...
- POJ-3275:Ranking the Cows(Floyd、bitset)
Ranking the Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3301 Accepted: 1511 ...
- 【Bitset】重识
---------------------------------------------------------------------------- 一题题目: 一题题解: 这个题目哪来入门再好不 ...
- USACO 2007 “March Gold” Ranking the Cows
题目链接:https://www.luogu.org/problemnew/show/P2881 题目链接:https://vjudge.net/problem/POJ-3275 题目大意 给定标号为 ...
- poj 3275 "Ranking the Cows"(DFS or Floyd+bitset<>)
传送门 题意: 农场主 FJ 有 n 头奶牛,现在给你 m 对关系(x,y)表示奶牛x的产奶速率高于奶牛y: FJ 想按照奶牛的产奶速率由高到低排列这些奶牛,但是这 m 对关系可能不能精确确定这 n ...
随机推荐
- javascript学习笔记(5
1.string Array Date Math 内置对象的属性和方法? 答案: ①String 字符串 属性 :length 获取字符串长度 方法: indexOf() 从左到右检索子字符串在原 ...
- linux计划任务运行php文件的方法分享
在linux下,借助crontab,设置计划任务每天6点10分执行filename.php文件,写入一行时间到log日志中. 创建计划任务的脚本: dos2unix /path/to/filename ...
- vb6-很简单的配置密码验证提示
'很简单的配置密码验证提示 Dim add As String add = Trim(InputBox("请输入配置密码", "报表配置")) If add = ...
- 长安CS15_手动——16款
一.输入数据 1.CAN总线描述:位置,颜色,速率,总线类型 1)位置:OBD 2)颜色:3) 速率:500k 4)总线类型:HSCAN 5)测试时间:2016.5.4 2.车辆特征 1)排量:1.5 ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化
链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...
- android studio如何开启与禁用版本控制vcs
1.开启
- 一个Makefile
CC = g++ CCFLAGS = -O3 -DNDEBUG INC = -I ../../include SRC = $(wildcard *.cpp) OBJ = $(patsubst %.cp ...
- poj 1659 Frogs' Neighborhood (DFS)
http://poj.org/problem?id=1659 Frogs' Neighborhood Time Limit: 5000MS Memory Limit: 10000K Total S ...
- 1044: [HAOI2008]木棍分割 - BZOJ
Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍被分成了很多段,要求满足总长度最大的一段长 ...
- 839. Optimal Marks - SPOJ
You are given an undirected graph G(V, E). Each vertex has a mark which is an integer from the range ...