【题目链接】:http://codeforces.com/problemset/problem/229/C

【题意】



给你一张完全图;

然后1个人从中选择m条边;

然后另外一个人从中选择剩余的n*(n-1)/2-m条边;

在这两个人分别选出的两张图中;

问你构成的长度为3的环的个数;

【题解】



先考虑完全图;

完全图中长度为3的环的个数为

C(n,3)

然后再考虑“分割”的这一过程毁掉了多少个环;

考虑A图中的某个点x;

假设它的度数为du[x];

则B图中对应的点x

它的度数应该为n-1-du[x];

(完全图中,每个点的度数都为n-1)

这样;

我们就能找到;

以x为一个点的,长度为3的环;被破坏的个数;

->du[x]*(n-1-du[x]);

即在x这个位置发出两条边(两张不同的图上);

假设出度分别为y和z

则肯定有边能够把y和z连在一起的;(完全图);

然后因为这两条边在不同的图上;

所以肯定是被破坏掉的一个环;

把所有的点被破坏的环的个数累加起来就好;

这里还需要注意一点吧.

就是上面说到的y和z;

必然有一个点我们会重复枚举到;

(但枚举的时候其实还是对应的这个x-y-z,也即重复了);

所以需要除2处理;

因为x,y,z不可能全部都在同一个图上(不然就不是被破坏的环了);

(对应{x},{y,z}或者是{x,y}{z},{x,z}{y},但无论如何都会重复枚举到这个已经算过的环,且只会多算一次);

所以只需要除2就好;

(不用scanf会超。)



【Number Of WA】



1



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6+100; int n,m,x,y;
LL du[N],temp,ans; int main(){
//Open();
//Close();//scanf,puts,printf not use
//init??????
scanf("%d%d",&n,&m);
rep1(i,1,m){
scanf("%d%d",&x,&y);
du[x]++,du[y]++;
}
rep1(i,1,n){
temp = temp + du[i]*(n-1-du[i]);
}
ans = 1LL*n*(n-1)*(n-2)/6 - temp/2;
printf("%I64d\n",ans);
return 0;
}

【codeforces 229C】Triangles的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【25.33%】【codeforces 552D】Vanya and Triangles

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 553C】Love Triangles

    [题目链接]:http://codeforces.com/problemset/problem/553/C [题意] 给你n个点,m条边; 每种边有2两种类型; 让你补充剩下的边,构造一个完全图; 使 ...

  4. 【41.43%】【codeforces 560C】Gerald's Hexagon

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. 2015 Multi-University Training Contest 9 hdu 5396 Expression

    Expression Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  2. ie6下position:fixed定位问题

    1. *html{ background-image:url(about:blank); background-attachment:fixed;}2.将需要用固定定位的元素中加上_position: ...

  3. BA--干球温度、露点温度和湿球温度--概念

    1. 干球温度.露点温度和湿球温度 dry bulb temperature, dew temperature, and wet-bulb temperature 摘要:未饱和湿空气中水蒸汽处于过热状 ...

  4. test environment bug

    pxj::EsgServiceImpl.kmsProcess->Get:ESG JAR return data is:{"code":10000,"data&quo ...

  5. [SharePoint2010开发入门经典]创建你的第一个SPS2010程序

    本章概要: 1.创建一个解决方案,使他能读写数据从列表中,使用服务器端对象模型和可视的web部件 2.使用VS2010构建部署解决方案 3.使用图标web部件渲染列表数据 4.在一个解决方案中集成不同 ...

  6. Leetcode_299_Bulls and Cows

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/50768550 You are playing the fo ...

  7. DesignPattern_Java:Factory Method Pattern

    工厂方法模式 Factory Method :(虚拟构造函数模式 Virtual Constructor,多态性工厂模式 Ploymorphic Facoty) Define an interface ...

  8. 笔试题&amp;面试题:给定n个数,要求比較次数1.5n同一时候找出最大值和最小值

    写出一个算法,对给定的n个数的序列,返回序列中的最大和最小的数. 设计出一个算法,仅仅须要运行1.5n次比較就能找到序列中最大和最小的数吗?是否能再少? 分析:要求比較次数为1.5n,使用一般的逐个遍 ...

  9. Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires

    Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires ...

  10. Android自己定义控件系列三:自己定义开关button(二)

    接上一篇自己定义开关button(一)的内容继续.上一次实现了一个开关button的基本功能.即自己定义了一个控件.开关button,实现了点击切换开关状态的功能.今天我们想在此基础之上.进一步实现触 ...