【CF771A】Bear and Friendship Condition】的更多相关文章

题目大意:给定一张无向图,要求如果 A 与 B 之间有边,B 与 C 之间有边,那么 A 与 C 之间也需要有边.问这张图是否满足要求. 题解:根据以上性质,即:A 与 B 有关系,B 与 C 有关系,那么 A 和 C 也要有关系,因此可以采用并查集加以维护,维护关系的同时顺便维护各个联通块的大小,若符合题目要求,则同一个联通块中的点必须均有关系.因此,最后计算一下每个联通块的应有关系数和最初所给的关系数比较,相等则符合,反之,不符合. 代码如下 #include <bits/stdc++.h>…
[题目链接]:http://codeforces.com/contest/791/problem/B [题意] 给你m对朋友关系; 如果x-y是朋友,y-z是朋友 要求x-z也是朋友. 问你所给的图是否符合 [题解] 用并查集处理出每个朋友"团"的大小->就是连通块 然后这个连通块里面应该要有x*(x-1)/2条边; 按照这个规则,求出应该有的边数; 然后和所给的m对比; 相同则YES,否则NO [完整代码] #include <bits/stdc++.h> usin…
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Bear Limak examines a social network. Its main functionality is that two members can become friends (then th…
B. Bear and Friendship Condition time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bear Limak examines a social network. Its main functionality is that two members can become friends (then th…
B. Bear and Friendship Condition time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bear Limak examines a social network. Its main functionality is that two members can become friends (then th…
B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pic…
[CF573D]Bear and Cavalry 题意:有n个人和n匹马,第i个人对应第i匹马.第i个人能力值ai,第i匹马能力值bi,第i个人骑第j匹马的总能力值为ai*bj,整个军队的总能力值为$\sum a_ib_j$(一个人只能骑一匹马,一匹马只能被一个人骑).有一个要求:每个人都不能骑自己对应的马.让你制定骑马方案,使得整个军队的总能力值最大.现在有q个操作,每次给出a,b,交换a和b对应的马.每次操作后你都需要输出最大的总能力值. $n\le 30000,q\le 10000$ 题解…
[CF679D]Bear and Chase 题意:近日,鼠国的头号通缉犯,神出鬼没的怪盗——Joker正于摩登市出没!对于名侦探Jack来说,这正是将其捉拿归案的大号时机.形式化地,摩登市可以看成一张 $n$ 个点,$m$ 条边的简单无向连通图.Jack有一个神奇的探测器:MC(Mouse Chaser).当Jack在某个城市使用MC时,MC会显示Joker所在城市与Jack所在城市之间的距离(即最短路所经过的边数).Jack只有两天的时间捉拿Joker,具体过程如下: 1.第一天,Joker…
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Bear Limak examines a social network. Its main functionality is that two members can become friends (then th…
[CF573E]Bear and Bowling 题面 洛谷 题解 首先有一个贪心的结论: 我们一次加入每个数,对于\(\forall i\),位置\(i\)的贡献为\(V_i = k_i\times a_i+b_i\),其中\(k_i\)为位置\(i\)之前被选的数的个数,\(b_i\)为\(i\)之后被选的数的和. 那么我们每次选这个贡献最大的位置一定最优. 然后来证一下这个结论的正确性(直接蒯了\(\text {I} \color{#FF0000} {\text {tst}}\)的): 引…