大意: 给定$n$结点无向图, 共n条边, 有重边无自环, 求有多少点对(u,v), 满足经过u和v的边数>=p

可以用双指针先求出所有$deg_u+deg_v \ge p$的点对, 但这样会多算一些有公共边的

再枚举边, 减去 $deg_u+deg_v-cnt(u,v) < p$的即可

其中$deg$为点的度数, $cnt(u,v)$为$u$与$v$之间的边数

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#define REP(i,a,n) for(int i=a;i<=n;++i) using namespace std;
typedef long long ll;
typedef pair<int,int> pii; const int N = 2e6+10;
map<pair<int,int>,int> g;
int deg[N], n, p; int main() {
scanf("%d%d", &n, &p);
REP(i,1,n) {
int u, v;
scanf("%d%d", &u, &v);
if (u>v) swap(u,v);
++g[pii(u,v)],++deg[u],++deg[v];
}
ll ans = 0;
for (auto it:g) {
int x=it.first.first,y=it.first.second;
if (deg[x]+deg[y]>=p&&deg[x]+deg[y]-it.second<p) --ans;
}
sort(deg+1,deg+1+n);
int now = n;
REP(i,1,n) {
while (now>i&&deg[now]+deg[i]>=p) --now;
ans += n-max(i,now);
}
printf("%lld\n",ans);
}

Bug in Code CodeForces - 420C (计数,图论)的更多相关文章

  1. codeforce 421D D. Bug in Code

    题目链接: http://codeforces.com/problemset/problem/421/D D. Bug in Code time limit per test 1 secondmemo ...

  2. SQL Server 2017的Linked Server配置触发的bug“Exception Code = c0000005 EXCEPTION_ACCESS_VIOLATION”

    SQL Server 2017的Linked Server配置触发的bug"Exception Code    = c0000005 EXCEPTION_ACCESS_VIOLATION&q ...

  3. codeforces 421d bug in code

    题目链接:http://codeforces.com/problemset/problem/421/D 题目大意:每个人说出自己认为的背锅的两个人,最后大BOSS找两个人来背锅,要求至少符合p个人的想 ...

  4. Educational Codeforces Round 69 E - Culture Code (最短路计数+线段树优化建图)

    题意:有n个空心物品,每个物品有外部体积outi和内部体积ini,如果ini>outj,那么j就可以套在i里面.现在我们要选出n个物品的一个子集,这个子集内的k个物品全部套在一起,且剩下的物品都 ...

  5. IOS bug之Code Sign error:Provisioning profile

    刚才解决一个版本冲突的bug,记在了博客里,这让我想起了另外一个bug,当时犹豫公司的开发者账号过期了,我打开应用运行时提示Code Sign error:Provisioning profile   ...

  6. Code the Tree(图论,树)

    ZOJ Problem Set - 1097 Code the Tree Time Limit: 2 Seconds      Memory Limit: 65536 KB A tree (i.e. ...

  7. CodeForces 558E(计数排序+线段树优化)

    题意:一个长度为n的字符串(只包含26个小字母)有q次操作 对于每次操作 给一个区间 和k k为1把该区间的字符不降序排序 k为0把该区间的字符不升序排序 求q次操作后所得字符串 思路: 该题数据规模 ...

  8. Bug in Code

    Coder-Strike 2014 - Finals (online edition, Div. 1) C:http://codeforces.com/problemset/problem/420/C ...

  9. Pave the Parallelepiped CodeForces - 1007B (计数)

    大意: 给定A,B,C, 求有多少个三元组$(a,b,c)$, 满足$a \le b \le c$, 且以若干个$(a,b,c)$为三边的长方体能填满边长(A,B,C)的长方体. 暴力枚举出$A,B, ...

随机推荐

  1. VNC的安装和常用命令

    主要参考文章:http://www.cnblogs.com/coderzh/archive/2008/07/16/1243990.html                         http:/ ...

  2. Python入门之获取当前所在目录的方法详解

    #本文给大家讲解的是使用python获取当前所在目录的方法以及相关示例,非常的清晰简单,有需要的小伙伴可以参考下 sys.path 模块搜索路径的字符串列表.由环境变量PYTHONPATH初始化得到. ...

  3. linux内核分析 第六周

    一.进程的描述 为了管理进程,内核必须对每个进程进行清晰的描述,进程描述符提供了内核所需了解的进程信息. 1.进程控制块PCB--task_struct 进程状态 进程打开的文件 进程优先级信息 2. ...

  4. 瘋子C语言笔记 (string)

    1.strstr() 函数 搜索一个字符串在另一个字符串中的第一次出现.找到所搜索的字符串,则该函数返回第一次匹配的字符串的地址:如果未找到所搜索的字符串,则返回NULL. 2.strcat() 函数 ...

  5. git如何生成指定两个commit之间的补丁

    答:git format-patch <base commit id>..<latest commit id> 如git log输出以下内容: commit 2222222 y ...

  6. BZOJ 5424: 烧桥计划

    BZOJ 5424: 烧桥计划 目前暂居rk1QAQ 首先,设\(f[i][k]\)为前i个点中,选了第i个点,总共选了k个点的答案.那么就有: \[f[i][k]=min_{j<i}\{f[j ...

  7. BZOJ3942: [Usaco2015 Feb]Censoring 栈+KMP

    Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...

  8. [不屈的复习] - http://how2j.cn/

    http://how2j.cn/ 该教程网站分得比较规整!

  9. UVa 1626 括号序列(矩阵连乘)

    https://vjudge.net/problem/UVA-1626 题意: 输入一个由 "(" . ")" . "[" . " ...

  10. Django Python MySQL Linux 开发环境搭建

    Django Python MySQL Linux 开发环境搭建 1.安装Python 进行Python开发,首先必须安装python,对于linux 或者Mac 用户,python已经预装. 在命令 ...