题目描述

N个点m条边,每个点有一个点权a。
对于任意一个三元环(j,j,k)(i<j<k),它的贡献
为max(ai,aj,ak) 
求所有三元环的贡献和。
N<100000,,m<250000。

输入

The first line of the standard input contains two integers  n and m (1<=N<=100000,1<=M<=250000) separated by a single space and denoting the number of confectioners at the convention and the number of pairs of them that like each other. The participants of the convention are numbered from  1 to N, The second line contains n integers pi (1<=Pi<=1000000) separated by single spaces and denoting the requirements of respective confectioners for flour (in decagrams). The following m lines contain data about pairs of contestants that like each other. Each of these lines contains two integers ai and bi (1<=ai,bi<=n Ai<>Bi) separated by a single space. They denote that confectioners ai and bi like each other. We assume that all pairs of participants of the convention apart from the ones listed in the input would not like to bake cakes together. Each pair of confectioners appears at most once in the input.

输出

The first and only line of the standard output should contain a single integer - the quantity of flour that will be used by all teams in total, in decagrams.

样例输入

5 7
1 5 3 4 2
1 2
2 3
5 2
4 3
3 1
1 4
5 1

样例输出

14
Explanation of the example. The following three-person teams: (1,2,3),(1,2,5) and (1,3,4)require 5, 5 and 4 decagrams of flour to bake the cakes. In total 5+5+4=14 decagrams of flour are required.
 
 
三元环模板题,做法参见三元环讲解

#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int v[100010];
int head[250010];
int to[500010];
int next[500010];
int vis[100010];
int s[100010];
int n,m;
int x,y;
int tot;
ll ans;
vector<int>q[100010];
void add(int x,int y)
{
tot++;
next[tot]=head[x];
head[x]=tot;
to[tot]=y;
s[x]++;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&v[i]);
}
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
add(x,y);
add(y,x);
}
for(int i=1;i<=n;i++)
{
for(int j=head[i];j;j=next[j])
{
if(s[i]>s[to[j]]||(s[i]==s[to[j]]&&i<to[j]))
{
q[i].push_back(to[j]);
}
}
}
for(int now=1;now<=n;now++)
{
int len=q[now].size();
for(int i=0;i<len;i++)
{
vis[q[now][i]]=now;
}
for(int i=0;i<len;i++)
{
int point=q[now][i];
int size=q[point].size();
for(int j=0;j<size;j++)
{
if(vis[q[point][j]]==now)
{
ans+=max(v[now],max(v[point],v[q[point][j]]));
}
}
}
}
printf("%lld",ans);
}

BZOJ3498PA2009 Cakes——三元环的更多相关文章

  1. BZOJ.3498.[PA2009]Cakes(三元环 枚举)

    题目链接 感觉我可能学的假的(复杂度没问题,但是常数巨大). 一个比较真的说明见这儿:https://czyhe.me/blog/algorithm/3-mem-ring/3-mem-ring/. \ ...

  2. BZOJ3498: PA2009 Cakes(三元环)

    题意 题目链接 Sol 按照套路把边转成无向图,我们采取的策略是从权值大的向权值小的连边 然后从按权值从小到大枚举每个点,再枚举他们连出去的点\(v\) 如果\(v\)的度数\(\leqslant M ...

  3. BZOJ 3498 PA2009 Cakes(三元环处理)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3498 [题目大意] N个点m条边,每个点有一个点权a. 对于任意一个三元环(j,j,k ...

  4. BZOJ 3498: PA2009 Cakes 一类经典的三元环计数问题

    首先引入一个最常见的经典三元环问题. #include <bits/stdc++.h> using namespace std; const int maxn = 100005; vect ...

  5. Bzoj 3498 Cakes(三元环)

    题面(权限题就不放题面了) 题解 三元环模板题,按题意模拟即可. #include <cstdio> #include <cstring> #include <vecto ...

  6. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  7. Codeforces Gym 100342J Problem J. Triatrip 三元环

    题目链接: http://codeforces.com/gym/100342 题意: 求三元环的个数 题解: 用bitset分别统计每个点的出度的边和入度的边. 枚举每一条边(a,b),计算以b为出度 ...

  8. Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量

    Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...

  9. HDU 6184 Counting Stars 经典三元环计数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6184 题意: n个点m条边的无向图,问有多少个A-structure 其中A-structure满足V ...

随机推荐

  1. spring----bean的使用

    这篇文章不介绍spring的相关概念,只记录一下springbean的创建方式和使用方式. 一.bean的创建和调用 1.创建演示需要用到的类:Student.Teacher.Person packa ...

  2. 当Flutter遇到节流与防抖

    相信web前端的开发者都或多或少的遇到过节流与防抖的问题.函数节流和函数防抖,两者都是优化执行代码效率的一种手段.在一定时间内,代码执行的次数不一定是越多越好.相反,频繁的触发或者执行代码,会造成大量 ...

  3. Android 手机连不上电脑

    [个人经验] 给大家分享一下,最近Android开发中一个坑. 在Android开发中,有时会需要自己开发服务端,就需要连接自己的电脑. ①首先,我们得知道我们电脑的ip地址是多少: 开始菜单---- ...

  4. IntelliJ IDEA简介及简单操作

    IntelliJ IDEA简介         IDEA 全称IntelliJ IDEA,是用于java语言开发的集成环境(也可用于其他语言),IntelliJ在业界被公认为最好的java开发工具之一 ...

  5. 智能POS(轻餐、正餐同理)桌台页面已结金额,只做参考,不做对账使用

    智能POS桌台已结金额只用来做参考使用,不做对账保障: 已结金额只有桌台一次结账金额,若存在反结账或退款的情况则不会减去相应的已结金额: 点餐无桌台的订单,金额不做统计: 口碑订单.扫码点餐,金额不做 ...

  6. sqlserver 学习之分离与附加数据库

    在学习sqlserver数据库的过程中,我们会学习到有关一些听起来比较陌生的专用名词,比如说分离与附加这两个专有名词,对于我来说就是比较陌生的.好的,下面我们一起来学习一下吧.为了讲的通俗一点,下面以 ...

  7. PowerDesigner 使用教程(很具体,很实用)

    原文地址为:PowerDesigner 使用教程(很具体,很实用) 1.PowerDesigner 使用教程 从今日开始,每天一部分内容,在每个工作日,争取让大家天天都有的看,每天内容不会太多. 有错 ...

  8. SQLServer之修改标量值函数

    修改标量值函数注意事项 更改先前通过执行 CREATE FUNCTION 语句创建的现有 Transact-SQL 或 CLR 函数,但不更改权限,也不影响任何相关的函数.存储过程或触发器. 不能用 ...

  9. c/c++ 继承与多态 容器与继承3

    c/c++ 继承与多态 容器与继承2 巩固了容器里放智能指针的用法,但是有个问题,对于使用Basket类的用户来说,必须添加的是智能指针,如果能直接添加一个普通的类的对象的话,用起来就方便的多了,所以 ...

  10. Linux中Zabbix4.0的搭建

    Zabbix简介 Zabbix是一个高度集成的企业级开源网络监控解决方案,与Cacti.nagios类似,提供分布式监控以及集中的web管理界面.zabbix具备常见商业监控软件所具备的功能,例如主机 ...