题目描述

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. 版本控制工具(SVN/Git)介绍

    文章大纲 一.SVN介绍二.Git介绍三.IDEA使用SVN和Git四.总结五.参考文章   一.SVN介绍 1. SVN服务器搭建和使用 首先来下载和搭建SVN服务器,下载地址如下: http:// ...

  2. SpringBoot实现全文搜索

    • 全文搜索  • solr安装  • solr中文分词  • solr数据库导入  • solr数据查询  • solrj接口调用     1:

  3. power-virus

    http://0cx.cc/category/yunwei/ 介绍安全姿势 https://www.freebuf.com/articles/system/193557.html

  4. 如何提高 windows 的使用效率?--巧用运行命令

    windows 操作系统可以使用 win+R 运行一些命令执行任务,好处是:高效.快速.准确. 启动程序 将程序 chrome 写入以下注册表中, SOFTWARE\Microsoft\Windows ...

  5. 转 Angular2优质学习资源收集

    文档博客书籍类 官方网站: https://angular.io 中文站点: https://angular.cn Victor的blog(Victor是Angular路由模块的作者): https: ...

  6. 7 Best Free RAR Password Unlocker Software For Windows

    Here is the list of Best Free RAR Password Unlocker Software for Windows. These software run differe ...

  7. 明天研究下jpa直接像django一样生成

    https://blog.csdn.net/yztezhl/article/details/79390714 自动生成 教程-- https://blog.csdn.net/mxjesse/artic ...

  8. 第十届蓝桥杯省赛JavaB组个人题解

    前言 以下的第十届蓝桥杯Java B组省赛的题目题解只是我个人的题解,提供一些解题思路,仅作参考,如有错误,望大家指出,不甚感激,我会及时更改. 试题 A: 组队 ----- 答案:490 [问题描述 ...

  9. 《通过C#学Proto.Actor模型》之PID

    PID对象是代表Actor对象的进程,是能过Actor.Spawn(props)获取的:它有什么成员呢?既然代理Actor,首先有一个ID,标识自己是谁,Actor在Spawn时可以命名这个ID,否则 ...

  10. 使用maven时出现Failure to transfer 错误的解决方法

    在eclipse里使用maven,连接nexus私服. 添加依赖之后,总是报添加的依赖jar文件找不到,但是在nexus的库里面能找到这个依赖的jar文件,但是在本地的maven库里面找不到,于是我将 ...