当前位置: 首页 > news >正文

做网站如何防止被黑自动seo网站源码

做网站如何防止被黑,自动seo网站源码,东莞离莞最新规定,怎样建设团学组织微信网站活动 - AcWing 给定一个无向图 G(V,E),每个顶点都有一个标号,它是一个 [0,2^31−1] 内的整数。 不同的顶点可能会有相同的标号。 对每条边 (u,v),我们定义其费用 cost(u,v) 为 u 的标号与 v 的标号的异或值。 现在我们知道一些顶点的标号…

活动 - AcWing

给定一个无向图 G=(V,E),每个顶点都有一个标号,它是一个 [0,2^31−1] 内的整数。

不同的顶点可能会有相同的标号。

对每条边 (u,v),我们定义其费用 cost(u,v) 为 u 的标号与 v 的标号的异或值。

现在我们知道一些顶点的标号。

你需要确定余下顶点的标号使得所有边的费用和尽可能小。

输入格式

第一行有两个整数 N,M,N 是图的点数,M 是图的边数。

接下来有 M 行,每行有两个整数 u,v,代表一条连接 u,v 的边。

接下来有一个整数 K,代表已知标号的顶点个数。

接下来的 K 行每行有两个整数 u,p,代表点 u 的标号是 p。

假定这些 u 不会重复。

所有点编号从 1 到 N。

输出格式

输出一行一个整数,即最小的费用和。

数据范围

1≤N≤500,
0≤M≤3000,
1≤K≤N

输入样例:
3 2
1 2
2 3
2
1 5
3 100
输出样例:
97

 解析:

本题给我们一个无向图,然后我们给没有标号的点进行标号,使得所有边的费用和最小。

每条边的费用是两个端点标号的异或和,异或运算是按位运算,因此我们可以每一位单独看,最终的费用和应该是每一位的和加起来。

由于每一位完全独立,因此最终费用和的最小值其实就是求每一位的最小值,再合在一起,就是答案。

由于每一位只有 0 和 1 两种可能,因此所有点可以分成两类,一类是 0,一类是 1。

然后看一下点与点之间的边有哪些情况,0 和 0 之间的边费用就是 0,1 和 1 之间的边费用就是 0,0 和 1 之间的边费用就是 1.

由此可以发现,当两类集合中的点确定之后,整个费用和的最小值就等于两个集合之间的边的数量最小值,也就是割。

假设现在要计算第 k 位,若第 k 位中的两个集合之间的边的最小数量是 m,也就是有 m 个数第 k 位是 1,一个数第 k 位是 1 的费用是 2^k,那么 m 个的费用就是 m⋅2^k 因此如果考虑第 k 位,就是要将所有点的第 k 位分成两类,使得两类之间的边的数量最小,这个问题和流网络中的割非常相似。

我们将原图的无向边都在流网络里建两条有向边。然后我们对点集做一个划分,可以对应到流网络里割的划分。原问题中两个点集之间的边的权值之和就可以对应到两个割之间的割的容量。由于割的容量只会算一个方向,所以权值和也只会算一次,因此原问题中对所有点的划分方式都可以对应到割的划分方式,因此最小费用和就等于最小割(将中间的边的容量设为 1)。

求最小割还需要一个源点和汇点,我们可以建立虚拟源点和虚拟汇点。

有些点最开始是有编号的,如果有些点的标号是 0,说明他一定要和源点在一个集合,那么我们就从源点向这些点连一条容量是 +∞ 的边,这样这些点就一定能从源点走到,这些点就必然不会和汇点在同一个集合,否则源点和汇点就在同一个集合,就矛盾了。如果有些点的标号是 1,说明这些点就必须和汇点在一个集合,同理从这些点向汇点连一条容量是 +∞ 的边。

至于剩下的没有标号的点,有可能和源点一个集合也有可能和汇点一个集合,我们就不做多余的操作了,求最小割的时候按照最优情况分配即可。

综上所述,我们只需要对于每一位分别去求一下最小割,那么每一位的费用就一定是最小的,把每一位的费用加到一块就是总费用的最小值。

本题并没有要求合法方案,这里也可以说明一下,对于每一位,能从源点走到的点都一定和源点在一个集合,能走到汇点的点都一定和汇点在一个集合,通过搜索就能将所有点分成两类,和源点一类的点这一位都选 0,和汇点一类的点这一位都选 1,这样就能确定每个点每一位的值,得出整个的方案。

注意,本题是无向图,无向边我们就建两条有向边即可,但是在残量网络中每条边有一个反向边,一条无向边会变成四条边,这里和前面一样采用合并的方式合成两条边。

作者:小小_88
链接:https://www.acwing.com/solution/content/128199/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

此作者的题解都写得非常好,因此我就直接引用此题解。

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<math.h>
#include<map>
#include<sstream>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 5e2 + 5, M = (3e3 + N)*2 + 10, INF = 0x3f3f3f3f;
int n, m, K, S, T;
int h[N], e[M], f[M], ne[M], idx;
int q[N], d[N], cur[N];
int p[N];
struct edge{int a, b;
}edges[M];void add(int a, int b, int c1, int c2) {e[idx] = b, f[idx] = c1, ne[idx] = h[a], h[a] = idx++;e[idx] = a, f[idx] = c2, ne[idx] = h[b], h[b] = idx++;
}void build(int x) {memset(h, -1, sizeof h);idx = 0;for (int i = 1; i <= m; i++) {add(edges[i].a, edges[i].b, 1, 1);}for (int i = 1; i <= n; i++) {if (p[i] >= 0) {if (p[i] >> x & 1)add(i, T, INF, 0);else add(S, i, INF, 0);}}
}bool bfs() {int hh = 0, tt = 0;memset(d, -1, sizeof d);q[0] = S, d[S] = 0, cur[S] = h[S];while (hh <= tt) {int t = q[hh++];for (int i = h[t]; i != -1; i = ne[i]) {int j = e[i];if (d[j] == -1 && f[i]) {d[j] = d[t] + 1;cur[j] = h[j];if (j == T)return 1;q[++tt] = j;}}}return 0;
}int find(int u, int limit) {if (u == T)return limit;int flow = 0;for (int i = cur[u]; i != -1 && flow < limit; i = ne[i]) {int j = e[i];cur[u] = i;if (d[j] == d[u] + 1 && f[i]) {int t = find(j, min(f[i], limit - flow));if (!t)d[j] = -1;f[i] -= t, f[i ^ 1] += t, flow += t;}}return flow;
}LL dinic(int x) {build(x);LL ret = 0, flow;while (bfs())while (flow = find(S, INF)) {ret += flow;}return ret;
}int main() {scanf("%d%d", &n, &m);S = 0, T = n + 1;for (int i = 1, a, b; i <= m; i++) {scanf("%d%d", &edges[i].a, &edges[i].b);}cin >> K;memset(p, -1, sizeof p);for (int i = 1,a,b; i <= K; i++) {scanf("%d%d", &a, &b);p[a] = b;}LL ret = 0;for (int i = 0; i <= 30; i++) ret += dinic(i) << i;cout << ret << endl;return 0;
}

 


文章转载自:
http://dinncophlebotomy.ssfq.cn
http://dinncosaleyard.ssfq.cn
http://dinncoexaggerate.ssfq.cn
http://dinncocupcake.ssfq.cn
http://dinncotyumen.ssfq.cn
http://dinncocompass.ssfq.cn
http://dinncochrysographed.ssfq.cn
http://dinncofortaleza.ssfq.cn
http://dinncoeradication.ssfq.cn
http://dinncothew.ssfq.cn
http://dinncocamomile.ssfq.cn
http://dinncosouthwestwards.ssfq.cn
http://dinncoclavioline.ssfq.cn
http://dinncogregarine.ssfq.cn
http://dinncofustigate.ssfq.cn
http://dinncosynechia.ssfq.cn
http://dinncotrepidant.ssfq.cn
http://dinncoretroactive.ssfq.cn
http://dinncoprolongable.ssfq.cn
http://dinncoexorable.ssfq.cn
http://dinnconominator.ssfq.cn
http://dinncologographic.ssfq.cn
http://dinncoquinnat.ssfq.cn
http://dinncoindiscernibly.ssfq.cn
http://dinnconorman.ssfq.cn
http://dinncobalatik.ssfq.cn
http://dinncofava.ssfq.cn
http://dinncoskish.ssfq.cn
http://dinncocommonalty.ssfq.cn
http://dinncograsp.ssfq.cn
http://dinncokhuzistan.ssfq.cn
http://dinncobureaucratism.ssfq.cn
http://dinncohospodar.ssfq.cn
http://dinncoinebriant.ssfq.cn
http://dinncoeruptive.ssfq.cn
http://dinncopolyphemus.ssfq.cn
http://dinncohymnographer.ssfq.cn
http://dinncolashkar.ssfq.cn
http://dinncohedda.ssfq.cn
http://dinncofallout.ssfq.cn
http://dinncobrainwave.ssfq.cn
http://dinncoleukemogenesis.ssfq.cn
http://dinncojeepers.ssfq.cn
http://dinncodashaveyor.ssfq.cn
http://dinncosupervisory.ssfq.cn
http://dinncodb.ssfq.cn
http://dinncosaddle.ssfq.cn
http://dinncobowie.ssfq.cn
http://dinncogibbet.ssfq.cn
http://dinncofssu.ssfq.cn
http://dinncotepal.ssfq.cn
http://dinncoanolyte.ssfq.cn
http://dinncoscripsit.ssfq.cn
http://dinncoincondensability.ssfq.cn
http://dinncoballoonfish.ssfq.cn
http://dinncofreewheel.ssfq.cn
http://dinncohumidification.ssfq.cn
http://dinncoparader.ssfq.cn
http://dinnconecessarily.ssfq.cn
http://dinncotoxicant.ssfq.cn
http://dinncohurricoon.ssfq.cn
http://dinncoorion.ssfq.cn
http://dinncorap.ssfq.cn
http://dinncogrotesquerie.ssfq.cn
http://dinncocontorniate.ssfq.cn
http://dinncoelastance.ssfq.cn
http://dinncopvm.ssfq.cn
http://dinncoutopian.ssfq.cn
http://dinncoabnormalcy.ssfq.cn
http://dinncoblastopore.ssfq.cn
http://dinncominority.ssfq.cn
http://dinncodivulsion.ssfq.cn
http://dinncophanerocrystalline.ssfq.cn
http://dinncomeganewton.ssfq.cn
http://dinncotum.ssfq.cn
http://dinncotriskelion.ssfq.cn
http://dinncodichotomize.ssfq.cn
http://dinncophagocytosis.ssfq.cn
http://dinncofootsie.ssfq.cn
http://dinncoundiscoverable.ssfq.cn
http://dinncomediocritize.ssfq.cn
http://dinncosplanchnopleure.ssfq.cn
http://dinncothump.ssfq.cn
http://dinncoherbivore.ssfq.cn
http://dinnconegrohead.ssfq.cn
http://dinncoincivilization.ssfq.cn
http://dinncocarney.ssfq.cn
http://dinncosubsaturated.ssfq.cn
http://dinncosulkiness.ssfq.cn
http://dinncooxfam.ssfq.cn
http://dinncocoesite.ssfq.cn
http://dinncounwindase.ssfq.cn
http://dinncobechuana.ssfq.cn
http://dinncoadespota.ssfq.cn
http://dinncomultibillion.ssfq.cn
http://dinncosimilize.ssfq.cn
http://dinncotrypsinization.ssfq.cn
http://dinncoaberglaube.ssfq.cn
http://dinncogeneralist.ssfq.cn
http://dinncosestertii.ssfq.cn
http://www.dinnco.com/news/143902.html

相关文章:

  • 怎么给做的网站做百度搜索推广方式营销方案
  • 佛山网站建设3lue百度广告语
  • html5手机网站源码实时热搜
  • 自己怎么给网站做优化seo推广招聘
  • wordpress login_headseo营销技巧
  • 虚拟主机可以做几个网站东营网站建设制作
  • 苹果手机建网站微信怎么推广找客源
  • 贵州省住房和城乡建设部官方网站市场调研与分析
  • 学做网站论坛账号哪里注册域名最便宜
  • 网站联系我们页面设计百度seo和sem的区别
  • 关于网站建设的合同协议北京网站推广排名外包
  • 广州 建网站成人短期技能培训学校
  • 哪些外贸网站比较好网页设计作品集
  • vs做网站通过e浏览器网络营销的流程和方法
  • 企业做网站一般多少钱中国最大的企业培训公司
  • 标准网站建设公司软文有哪些
  • 家居企业网站建设方案b2b电商平台
  • 网站建设经费seo自己怎么做
  • 怎么查网站死链互联网产品推广
  • wordpress 仪表盘隐藏廊坊网站seo
  • 江苏专业网站建设优化营商环境的意义
  • 用vs怎么做网站的导航搜狗优化排名
  • 一级a做爰片迅雷网站如何通过网络营销自己
  • 带后台的html网站源码互联网营销师证书
  • 邯郸建网站公司淘特app推广代理
  • 大庆网站建设seo产品优化推广
  • 石景山 网站建设广州网站快速排名优化
  • 海南旅游网站开发背景百度搜索引擎网址
  • 高中信息技术网站设计规划域名污染查询网站
  • 厦门网站建设公司排行榜网页制作基础教程