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

题目描述 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 deno…
题目链接 感觉我可能学的假的(复杂度没问题,但是常数巨大). 一个比较真的说明见这儿:https://czyhe.me/blog/algorithm/3-mem-ring/3-mem-ring/. \(Description\) n个点m条边的无向图,每个点有点权.对于任意一个三元环\((i,j,k),i<j<k\),其贡献为\(max\{a_i,a_j,a_k\}\).求所有三元环的贡献和. 一般的三元环计数问题:根据出度是否\(\leq\sqrt m\)将点分为两类. 对于\(dgr[x]…
题意 题目链接 Sol 按照套路把边转成无向图,我们采取的策略是从权值大的向权值小的连边 然后从按权值从小到大枚举每个点,再枚举他们连出去的点\(v\) 如果\(v\)的度数\(\leqslant M\),那么就再暴力枚举\(v\)连出去的点\(t\),看\(u\)与\(t\)是否联通(打标记) 否则暴力枚举\(u\)连出去的点\(t\),看\(v\)与\(t\)是否联通(直接hash表) 复杂度为\(O(M \sqrt{M})\) #include<bits/stdc++.h> #defin…
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3498 [题目大意] N个点m条边,每个点有一个点权a. 对于任意一个三元环(j,j,k)其贡献为max(a[i],a[j],a[k]),请你求出贡献值之和. [题解] 我们将无向边转化成从权值大的点指向权值小的点的有向边,按权值从小到大的顺序枚举起始点,枚举相连的点,如果其出度小于sqrt(m),那么枚举与其相连的点,判断是否和起始点相连,否则,枚举起始点相连的点,判断是否和枚举点相…
首先引入一个最常见的经典三元环问题. #include <bits/stdc++.h> using namespace std; const int maxn = 100005; vector <int> g[maxn], low, high; map <int, int> mp[maxn]; int n, m, in[maxn], vis[maxn]; int main() { scanf("%d %d", &n,&m); for(…
题面(权限题就不放题面了) 题解 三元环模板题,按题意模拟即可. #include <cstdio> #include <cstring> #include <vector> using std::vector; const int N = 1e5 + 10, M = 2.5e5 + 10; int n, m, a[N], deg[N], u[M], v[M], vis[N], tmp; long long ans; vector<int> to[N]; i…
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The travel agency “Four Russians” is offering the new service for their clients. Unlike other agencies that only suggest one-way…
题目链接: http://codeforces.com/gym/100342 题意: 求三元环的个数 题解: 用bitset分别统计每个点的出度的边和入度的边. 枚举每一条边(a,b),计算以b为出度的边的终点构成的点集和以a为入度的边的起点够成的点集的交集,更新答案. 代码: #include<iostream> #include<cstring> #include<cstdio> #include<bitset> using namespace std;…
Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The travel agency “Four Russians” is offering the new service for their clients. Unlike other agencies that only suggest one-way…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6184 题意: n个点m条边的无向图,问有多少个A-structure 其中A-structure满足V=(A,B,C,D) && E=(AB,BC,CD,DA,AC) 解法: 可以看出A-structure是由两个有公共边的三元环构成的,然后就变成了这道题. http://www.cnblogs.com/spfa/p/7495438.html #include <stdio.h>…