HDU 3435 KM A new Graph Game】的更多相关文章

和HDU 3488一样的,只不过要判断一下是否有解. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; + ; const int INF = 0x3f3f3f3f; int n, m; int W[maxn][maxn], lft[maxn]; int slack…
A new Graph Game Problem Description An undirected graph is a graph in which the nodes are connected by undirected arcs. An undirected arc is an edge that has no arrow. Both ends of an undirected arc are equivalent--there is no head or tail. Therefor…
A new Graph Game Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2360    Accepted Submission(s): 951 Problem Description An undirected graph is a graph in which the nodes are connected by undire…
HDU 5957 Query on a graph 2016ACM/ICPC亚洲区沈阳站 题意 \(N(N \le 10^5)\)个点,\(N\)条边的连通图. 有\(M \le 10^5\)操作: \(MODIFY\ u\ k\ d,k \le 2\):距离点\(u\)不超过\(k\)的点的权值都加上\(d\). \(QUERY\ u\ k\):询问距离\(d\)不超过\(k\)的点权和. 思路 图的形状时一个环和若干树枝构成. 考虑\(k=1\)时,分两种情况讨论: \(u\)在环上,则需要…
http://acm.hdu.edu.cn/showproblem.php?pid=3435 #include <cstdio> #include <iostream> #include <cstring> #include <queue> #include <algorithm> #define inf 0x3f3f3f3f #define maxn 54444 using namespace std; queue<int>q; s…
http://acm.hdu.edu.cn/showproblem.php?pid=3435 题意:有n个点和m条边,你可以删去任意条边,使得所有点在一个哈密顿路径上,路径的权值得最小. 思路: 费用流,注意判断重边,否则会超时. #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<queue> using namespace std; ty…
Problem Description An undirected graph is a graph in which the nodes are connected by undirected arcs. An undirected arc is an edge that has no arrow. Both ends of an undirected arc are equivalent--there is no head or tail. Therefore, we represent a…
A new Graph Game Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1849    Accepted Submission(s): 802 Problem Description An undirected graph is a graph in which the nodes are connected by undir…
Tour Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2925    Accepted Submission(s): 1407 Problem Description In the kingdom of Henryy, there are N (2 <= N <= 200) cities, with M (M <= 30000…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2853 题目大意:二分图匹配费用流.①最大匹配②最小原配变动 解题思路: 如果去掉第二个要求,那么就是裸KM. 然而加上第二个要求,那么就需要一种新的建图方式. 建图 对于输入矩阵,每一条边,cost扩大K倍($K=n+1$) 对于原配,每一条边cost在扩大K倍基础上+1 KM 统计cost时,直接把cost整除K,然后累加. 并且Hash一下原配边的变动情况. 扩大K倍的作用 准确来说,K倍是为了…
http://acm.split.hdu.edu.cn/showproblem.php?pid=2255 带权匹配问题: #include <stdio.h> #include <algorithm> #include <string.h> #include <vector> using namespace std; #define maxn 330 #define INF 0xfffffff int maps[maxn][maxn], vx[maxn],…
题意: 一张完备二分图求最优完备匹配. SOL: 这题就不讲什么sol了...毕竟是裸的KM,不会的话可以看老人家的大白鼠,一些问题看代码注释.讲讲经历(悲惨的经历) 刚打完,自信地交上去发现MLE...一脸大雾...然后才开始看数据..300^4啊...看起来会炸的样子,那么加个优化好了.还是MLE!真是奇了怪了.然后就在提交里看别人是不是用的邻接表——清一色邻接矩阵!再想想KM搞的都是完备图啊邻接表和邻接矩阵用起来没什么不同.那么没问题啊?然后交来交去交了8次...直到zyh大神——虽然他从…
主题链接:pid=2454">http://acm.hdu.edu.cn/showproblem.php?pid=2454 Problem Description Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep love and yearns for the bound…
Mining Station on the Sea Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2997    Accepted Submission(s): 913 Problem Description The ocean is a treasure house of resources and the development o…
Special Fish Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2189    Accepted Submission(s): 826 Problem Description There is a kind of special fish in the East Lake where is closed to campus of…
http://acm.hdu.edu.cn/showproblem.php?pid=4862 选t<=k次,t条路要经过全部的点一次而且只一次. 建图是问题: 我自己最初就把n*m 个点分别放入X集合以及Y集合,再求最优匹配,然后连例子都过不了,并且事实上当时解释不了什么情况下不能得到结果.由于k此这个条件相当于没用上... 建图方法: 1.X集合和Y集合都放入n*m+k个点,X中前n*m个点和Y中前n*m个点之间.假设格子里的值相等.权就是(收益-耗费),不等就是(-耗费),由于要的是最大收益…
参考题解 二分图的最优匹配.图很容易建立.再处理相似度的时候.把每个权值扩大100倍.然后再对i==j时 特殊标记.使他们的权值再++1.后面选择的时候就很容易挑出.按原匹配 匹配的个数. 100*(double)(res%100)/n.即可得到第二问. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #…
题意 求二分图最小完备匹配. SOL 建个图那么方便的事情是吧...然后边权都是正的(好像根边权也没什么关系),既然要求最小那么把边权取个相反数跑个KM就好了.. CODE: /*========================================================================== # Last modified: 2016-02-16 19:55 # Filename: hdu1533.cpp # Description: ============…
Going Home Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3299    Accepted Submission(s): 1674 Problem Description On a grid map there are n little men and n houses. In each unit time, every l…
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10760    Accepted Submission(s): 4765 Problem Description 传说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子.这可是一件大事,关系到人民的住房问题啊.村里共有n间房间,刚好有n家老百姓,考虑…
以前用KM写过,现在再用费用流写. #include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <vector> #include <utility> #define abs(a) ((a)<0?-(a):(a)) #define maxn 210 #define oo 0x3f3f3f3f using namespace…
参考题解 这题注意有重边.. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; int n, m; int W[maxn][maxn], lft[maxn]; int Lx[maxn], Ly[maxn]; bool S[maxn], T[maxn]; int slack[maxn]; bool match(int u) { S[u] = true; ;…
#include<stdio.h> #include<math.h> #include<string.h> #define N 200 #define inf 999999999 int Max(int a,int b ) {     return a>b?a:b; } int Min(int a,int b) {     return a>b?b:a; } int map[N][N],lx[N],ly[N],s[N],t[N],link[N],n,m,ot…
为什么可以这样拆点在 这道题 都已经证明过 代码: 1 //题目上面说了"The only exception is that the first and the last city should be the same and this city is visited twice." 2 //我还以为是起点要使用两次,没想到题意就是全部点连接之后出入度都为1 3 4 //题意:有n座城市,m条带权有向边.有人想要游历所有城市,于是制定了计划:游历的路径是一个或者多个环,且所有城市都必…
题目:这里 题意: 相当于一开始给一个初始好了的无向完全图给你,然后给让你删除m条边,再给你一个点v,最后问你在剩下的图里从这个点v出发能到达所有边点的最小路径是多少? 一看是所有点的最小路径,一看就觉得是个bfs,记忆化搜一下然后加个优化什么的,由于数据不知道是个什么奇葩而且比赛中还改数据,所以很多人wa的莫名其妙, 过也过的莫名其妙,我虽然过了但觉得有点不靠谱,赛后看了https://async.icpc-camp.org/d/546-2016的题解思路写了一发,总感觉更靠谱一点. 之前自己…
///已知各点的度,推断是否为一个简单图 #include<stdio.h> #include<algorithm> #include<string.h> using namespace std; int a[1010]; bool cmp(int x,int y) { return x>y; } int main() { int t,n,i,j; scanf("%d",&t); while(t--) { int flag=1; sca…
题意:一个图有n个点,n条边,定义D(u,v)为u到v的距离,S(u,k)为所有D(u,v)<=k的节点v的集合 有m次询问(0<=k<=2): 1 u k d:将集合S(u,k)的所有节点的权值加d 2 u k:询问集合S(u,k)的所有节点的权值之和 析:把这个图树成两部分,一个是一个环,然后剩下的森林. 这个环可以用拓扑来求,看这个博客吧,讲的非常细了. http://blog.csdn.net/qq_31759205/article/details/75049074 代码如下:…
将一个无向图分成许多回路,回路点交集为空,点幷集为V.幷最小化回路边权和. #include <cstdio> #include <cstring> #include <queue> #include <vector> #define maxn 2010 #define oo 0x3f3f3f3f using namespace std; struct Edge { int u, v, c, f; Edge( int u, int v, int c, int…
其实打返祖边就相当于$x$到祖先这一段点(不包括两端)答案都要减$1$. 然后每个点最多减$1$次$1$. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b) for (int i(a); i >= (b); --i) #define MP make_pair #define fi first #de…
题意:给定一个N个点的零图,M次操作,添加或删除一条边,每一次操作以后,打印用1,2,...N/2条边构成的匹配数. 分析:因为N的范围很小,所以可以把点的枚举状态用二进制表示集合.用一维数组dp[S]表示二进制集合为S的点集的匹配数. 每次加边操作,从大到小遍历集合,dp[S]+=dp[S-u-v]:删边操作,从小到大遍历集合,dp[S]-=dp[S-u-v]. 预处理出每个1024之内每个数对应二进制含有1的个数,每次记录答案就将每个dp[S]加到ans[S对应的二进制个数]中. #incl…