Edge coloring of bipartite graph CodeForces - 600F (二分图染色)
大意:给定二分图, 求将边染色, 使得任意邻接边不同色且使用颜色种类数最少
最少颜色数即为最大度数, 要输出方案的话, 对于每一条边(u,v), 求出u,v能使用的最小的颜色$t0$,$t1$
若t0=t1, 直接染就行不会有冲突, 否则就染为t0, 这样的话可能产生冲突, 就将冲突的边换成t1, 依次递归下去
由于二分图的性质, 最终一定可以找到一条边不冲突
#include <iostream>
#include <algorithm>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std; const int N = 1e3+10, INF = 0x3f3f3f3f;
int a, b, m;
int g[N][N];
int f[2][N][N], c[N*N]; void dfs(int a, int b, int x, int y, int now, int pre) {
int to=f[b][y][now];
f[a][x][now]=y,f[b][y][now]=x;
if (!to) f[b][y][pre]=0;
else dfs(b,a,y,to,pre,now);
} int main() {
scanf("%d%d%d", &a, &b, &m);
int ans = 0;
REP(i,1,m) {
int u, v;
scanf("%d%d", &u, &v);
g[u][v] = i;
int t0=1,t1=1;
while (f[0][u][t0]) ++t0;
while (f[1][v][t1]) ++t1;
ans = max(ans, max(t0,t1));
if (t0==t1) f[0][u][t0] = v, f[1][v][t0] = u;
else dfs(0,1,u,v,t0,t1);
}
REP(i,1,a) REP(j,1,ans) if (f[0][i][j]) {
c[g[i][f[0][i][j]]]=j;
}
printf("%d\n", ans);
REP(i,1,m) printf("%d ", c[i]);
puts("");
}
Edge coloring of bipartite graph CodeForces - 600F (二分图染色)的更多相关文章
- CodeForces - 600F Edge coloring of bipartite graph
Discription You are given an undirected bipartite graph without multiple edges. You should paint the ...
- Educational Codeforces Round 2 Edge coloring of bipartite graph
题意: 输入一个二分图,用最少的颜色数给它的每条边染色,使得同一个顶点连的边中颜色互不相同. 输出至少需要的颜色数和任意一种染色方案. 分析: 证明不会,只说一下(偷瞄巨巨代码学到的)做法. 假设点的 ...
- AIM Tech Round (Div. 2) C. Graph and String 二分图染色
C. Graph and String 题目连接: http://codeforces.com/contest/624/problem/C Description One day student Va ...
- Codeforces 664D Graph Coloring 二分图染色
题意: 一个无向图的每条边为红色或蓝色,有这样一种操作:每次选一个点,使与其相邻的所有边的颜色翻转. 求解是否可以经过一系列操作使所有的边颜色相同,并输出最少操作次数和相应的点. 分析: 每个点要么选 ...
- HDU 5313——Bipartite Graph——————【二分图+dp+bitset优化】
Bipartite Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5313 Bipartite Graph(二分图染色+01背包水过)
Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...
- D - Beautiful Graph CodeForces - 1093D (二分图染色+方案数)
D - Beautiful Graph CodeForces - 1093D You are given an undirected unweighted graph consisting of nn ...
- 二分图点染色 BestCoder 1st Anniversary($) 1004 Bipartite Graph
题目传送门 /* 二分图点染色:这题就是将点分成两个集合就可以了,点染色用dfs做, 剩下的点放到点少的集合里去 官方解答:首先二分图可以分成两类点X和Y, 完全二分图的边数就是|X|*|Y|.我们的 ...
- Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths (二分图染色)
题意:有\(n\)个点和\(m\)条无向边,现在让你给你这\(m\)条边赋方向,但是要满足任意一条边的路径都不能大于\(1\),问是否有满足条件的构造方向,如果有,输出一个二进制串,表示所给的边的方向 ...
随机推荐
- linux服务器---squid限制
Squid连接限制 Squid可以有效的限制连接,指定哪些用户可以连接,指定哪些网站可以访问,这样就可以有效的利用服务器带宽. 1.限制指定网段不能连接.编辑配置文件”/etc/squid/squid ...
- mybatis项目启动报错 The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
启动项目报错 2018-02-26 17:09:51,535 ERROR [org.springframework.web.context.ContextLoader] - Context initi ...
- web前端----jQuery扩展(很重要!!)
1.jQuery扩展语法 把扩展的内容就可以写到xxxx.js文件了,在主文件中直接导入就行了. 用法1.$.xxx() $.extend({ "GDP": function () ...
- 20145222何志威《网络对抗》- Web安全基础实践
20145322何志威<网络对抗>Exp9 Web安全基础实践 基础问题回答 1.SQL注入原理,如何防御 SQL注入 就是通过把SQL命令插入到"Web表单递交"或& ...
- ssh服务的最佳实践
工作中ssh的最佳实践: 不要使用默认端口 禁止使用protocol version 1 (默认centos6/7已经禁止使用第一版了,但是centos5可能还有在用第一版本) 限制可登陆用户 设定空 ...
- Python3基础 str 通过拆分字符串与插入新的内容形成新的字符串
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 【LTE基础知识】SGLTE, SVLTE, CSFB, VoLTE【转】
本文转载自:https://blog.csdn.net/henryghx/article/details/18416405 4G网络下实现语音通话功能的技术共有三种——VoLTE.SGLTE(GSM ...
- 在ubuntu bionic下对基于qemu的arm64进行linux内核5.0.1版本的编译和运行
一.环境介绍 OS:ubuntu bionic 64bit 二.准备工作 2.1 安装必要的开发工具 sudo apt-get install git flex bison build-essenti ...
- JavaScript:Function/Object/prototype/__proto__
console.log(Object.__proto__===Function.prototype); //true console.log(Object.prototype.__proto__); ...
- [luogu 2458][SDOI2006]保安站岗
题目描述 五一来临,某地下超市为了便于疏通和指挥密集的人员和车辆,以免造成超市内的混乱和拥挤,准备临时从外单位调用部分保安来维持交通秩序. 已知整个地下超市的所有通道呈一棵树的形状:某些通道之间可以互 ...