G. Team Players
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn players numbered from 00 to n−1n−1 with ranks. The ii-th player has rank ii.

Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated using the following algorithm: let ii, jj, kk be the ranks of players in the team and i<j<ki<j<k, then the rank of the team is equal to A⋅i+B⋅j+C⋅kA⋅i+B⋅j+C⋅k.

You are given information about the pairs of players who have a conflict. Calculate the total sum of ranks over all possible valid teams modulo 264264.

Input

The first line contains two space-separated integers nn and mm (3≤n≤2⋅1053≤n≤2⋅105, 0≤m≤2⋅1050≤m≤2⋅105) — the number of players and the number of conflicting pairs.

The second line contains three space-separated integers AA, BB and CC (1≤A,B,C≤1061≤A,B,C≤106) — coefficients for team rank calculation.

Each of the next mm lines contains two space-separated integers uiui and vivi (0≤ui,vi<n,ui≠vi0≤ui,vi<n,ui≠vi) — pair of conflicting players.

It's guaranteed that each unordered pair of players appears in the input file no more than once.

Output

Print single integer — the total sum of ranks over all possible teams modulo 264264.

Examples
input
Copy
4 0
2 3 4
output
Copy
64
input
Copy
4 1
2 3 4
1 0
output
Copy
38
input
Copy
6 4
1 5 3
0 3
3 5
5 4
4 3
output
Copy
164
Note

In the first example all 44 teams are valid, i.e. triples: {0, 1, 2}, {0, 1, 3}, {0, 2, 3} {1, 2, 3}.

In the second example teams are following: {0, 2, 3}, {1, 2, 3}.

In the third example teams are following: {0, 1, 2}, {0, 1, 4}, {0, 1, 5}, {0, 2, 4}, {0, 2, 5}, {1, 2, 3}, {1, 2, 4}, {1, 2, 5}.

AC代码为:

#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x ;i <= y; ++ i)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<typename T>inline void read(T&x)
{
    char c;int sign = 1;x = 0;
    do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
    do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
    x *= sign;
}

const int N = 2e5 + 20;
ull a,b,c,n,m;
ull u[N],v[N],ans;
ull s1[N],s2[N],s3[N];
vector<int> g[N],f[N];

int main()
{
    read(n); read(m);
    read(a); read(b); read(c);
    rep(i,1,m)
    {
        read(u[i]); read(v[i]);
        if(u[i] > v[i]) swap(u[i],v[i]);
        g[u[i]].push_back(v[i]);
        f[v[i]].push_back(u[i]);
    }

    rep(i,0,n-1)
    {
        ull x = n - i - 1;
        ans += a * i * (x * (x - 1) / 2);
        ans += b * i * i * x;
        ans += c * i * ((ull)i * (i - 1) / 2);
    }

    rep(i,1,m)
    {
        s1[  0 ] += 1;
        s1[u[i]] -= 1;

        s1[ u[i] ] += n - u[i] - 2;
        s1[u[i]+1] -= n - u[i] - 2;

        s2[u[i]+1] += 1;
        s2[ v[i] ] -= 1;

        s2[ u[i] ] += u[i];
        s2[u[i]+1] -= u[i];

        s2[ v[i] ] += n - v[i] - 1;
        s2[v[i]+1] -= n - v[i] - 1;

        s3[v[i]+1] += 1;
        s3[  n   ] -= 1;

        s3[ v[i] ] += v[i] - 1;
        s3[v[i]+1] -= v[i] - 1;
    }

    rep(i,1,n) 
        s1[i] += s1[i - 1],
        s2[i] += s2[i - 1],
        s3[i] += s3[i - 1];

    rep(i,0,n - 1)
    {
        ans -= a * i * s1[i];
        ans -= b * i * s2[i];
        ans -= c * i * s3[i];
    }

    rep(i,0,n-1) sort(g[i].begin(),g[i].end());
    rep(i,0,n-1) sort(f[i].begin(),f[i].end());
    rep(i,0,n-1)
    {
        int sz = g[i].size();
        rep(j,0,sz - 1)
        {
            int k = j + 1;
            while(k < sz)
            {
                ans += a * i;
                ans += b * g[i][j];
                ans += c * g[i][k];
                k ++ ;
            }

            int SZ = g[g[i][j]].size();
            rep(q,0,SZ - 1)
            {
                ans += a * i;
                ans += b * g[i][j];
                ans += c * g[g[i][j]][q];
            }
        }

sz = f[i].size();
        rep(j,0,sz - 1)
        {
            int k = j + 1;
            while(k < sz)
            {
                ans += a * f[i][j];
                ans += b * f[i][k];
                ans += c * i;
                ++ k;
            }
        }
    }

    rep(i,0,n-1)
    {
        int sz = g[i].size();
        rep(j,0,sz - 1)
        {
            int t = j + 1,k = 0;
            int SZ = g[g[i][j]].size();
            while(t < sz && k < SZ)
            {
                if(g[i][t] == g[g[i][j]][k])
                {
                    ans -= a * i;
                    ans -= b * g[i][j];
                    ans -= c * g[i][t];
                    ++ t; ++ k;
                }
                else if(g[i][t] < g[g[i][j]][k]) ++ t;
                else ++ k;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

CodeForces985G Team Players的更多相关文章

  1. Codeforces 985G. Team Players

    Description 有 \(n\) 个人 , \(m\) 对人有冲突 , 你要从这 \(n\) 个人中选出三个人成为一组 , 使得同一组的人不存在一对有冲突 题面 Solution 容斥 答案=总 ...

  2. BZOJ.5407.girls/CF985G. Team Players(三元环计数+容斥)

    题面 传送门(bzoj) 传送门(CF) \(llx\)身边妹子成群,这天他需要从\(n\)个妹子中挑出\(3\)个出去浪,但是妹子之间会有冲突,表现为\(i,j\)之间连有一条边\((i,j)\), ...

  3. [CF985G]Team Players

    题意:给出一个图,求$\sum\limits_{\substack{i\lt j\lt k\\\nexists(i,j),(j,k),(i,k)}}Ai+Bj+Ck$ 挺好的一道题==,就是稍微毒了点 ...

  4. Codeforces 985G - Team Players(三元环)

    Codeforces 题目传送门 & 洛谷题目传送门 真·ycx 做啥题我就做啥题 考虑枚举 \(j\),我们预处理出 \(c1_i\) 表示与 \(i\) 相连的编号 \(<i\) 的 ...

  5. Ten Qualities of an Effective Team Player

    If you were choosing team members for a business team in your organization, who would the best team ...

  6. Model--汇总

    NSFileManager.NSURL.NSFileHandle.NSData.NSXMLParser.NSUserDefaults.NSKeyedArchiver.NSKeyedUnarchiver ...

  7. 《C#本质论》读书笔记(14)支持标准查询操作符的集合接口

      14.2.集合初始化器 使用集合初始化器,程序员可以采用和数组相似的方式,在集合的实例化期间用一套初始的成员来构造这个集合. 如果没有集合初始化器,就只有在集合实例化后才能显示添加到集合中--例如 ...

  8. ng-repeat的group

     http://blog.csdn.net/violet_day/article/details/17023219 一.obj包含 <!doctype html> <html ng- ...

  9. ios9基础知识(技能篇)

    NSFileManager.NSURL.NSFileHandle.NSData.NSXMLParser.NSUserDefaults.NSKeyedArchiver.NSKeyedUnarchiver ...

随机推荐

  1. 虚拟机添加硬盘RAID5并分区、格式化、挂载使用

    当全新安装了一块新的硬盘设备后,为了更充分.安全的利用硬盘空间首先要进行磁盘的分区,然后格式化,最后挂载使用. 1.开启虚拟机之前,先添加硬盘设备,在这里我添加了5块硬盘(5块磁盘,3块做RAID5, ...

  2. Linux下rpm仓库搭建

    一.概念 1.rpm是什么?在帮助文档里我们可以看到,rpm的名字是rpm package manage 的缩写, 从名字上看就可以知道rpm就是一个包管理工具.简单说rpm包就是把一些程序编译成二进 ...

  3. Comet OJ - 2019国庆欢乐赛 C题 两排房子

    ###题目链接### 题目大意:这里有横着的两排房子,给你每个房子的左端点和右端点.若两排房子中分别有两个房子 x y ,他们在横坐标上有重叠部分(端点重叠也算),则被称为 “对门” 关系. 问你总共 ...

  4. 基于docker实现redis高可用集群

    基于docker实现redis高可用集群 yls 2019-9-20 简介 基于docker和docker-compose 使用redis集群和sentinel集群,达到redis高可用,为缓存做铺垫 ...

  5. 装上linux后的准备工作

    A.修改对应网卡的IP地址的配置文件  1 2 3 4 5 6 7 8 # vi /etc/sysconfig/network-scripts/ifcfg-eth0   IPV6INIT=no #关闭 ...

  6. thinkphp5配合datatable插件分页后端处理程序

    thinkphp5配合datatable插件分页后端处理程序第一版DataTable.php v.1.0 <?php use think\Db; /** * DataTable.php. */ ...

  7. nyoj 8-一种排序 (贪心)

    8-一种排序 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:9 submit:18 题目描述: 现在有很多长方形,每一个长方形都有一个编号,这个编号 ...

  8. C语言程序设计100例之(17):百灯判亮

    例17   百灯判亮 问题描述 有序号为1.2.3.….99.100的100盏灯从左至右排成一横行,且每盏灯各由一个拉线开关控制着,最初它们全呈关闭状态.有100个小朋友,第1位走过来把凡是序号为1的 ...

  9. 安卓手机运行fedora

    安卓手机使用容器运行其他linux,一般两种: 1. termux + rootfs.img + proot,依赖api>=21,不必root但受限. 2. linuxdeploy + proo ...

  10. java基础开发环境安装(全)

    一.jdk安装(可以根据自己习惯选择合适安装路径) 1.jdk1.8下载地址:https://pan.baidu.com/s/1O9JQlFJ9cpkGCQL35cm_7g 提取码:pe2g 2.jd ...