LA 3523 圆桌骑士
来源:互联网 发布:wifi破解mac版 编辑:程序博客网 时间:2024/04/30 01:06
每一部分知识简单,合起来就容易出错了,慢慢敲,快了错误率以指数级别
上升
#include<cstdio>#include<cstring>#include<cmath>#include<queue>#include<stack>#include<iostream>#include<vector>#include<algorithm>using namespace std;typedef long long ll;const int MAXN = 1007;bool g[MAXN][MAXN];bool odd[MAXN];bool iscut[MAXN];struct edge {int u, v;};int bln[MAXN];int low[MAXN], dfn[MAXN];int color[MAXN];int nb, pt;vector<int> G[MAXN], bl[MAXN];stack<edge> sg;int dfs(int u, int fa) {dfn[u] = low[u] = ++pt;int i, child = 0, n = G[u].size();for(i = 0; i < n; i++) {int v = G[u][i];edge e = (edge) {u, v};if( !dfn[v] ) {child ++;sg.push(e);low[u] = min(low[u], dfs(v, u));if(low[v] >= dfn[u]) {iscut[u] = true;nb ++;bl[nb].clear();while( !sg.empty()) {edge tmp = sg.top();sg.pop();if( bln[tmp.u] != nb ) {bl[nb].push_back(tmp.u);bln[tmp.u] = nb;}if( bln[tmp.v] != nb) {bl[nb].push_back(tmp.v);bln[tmp.v] = nb;}if(tmp.u == u && tmp.v == v) break;}}}else if(dfn[v] < dfn[u] && v != fa) {sg.push(e);low[u] = min(low[u], dfn[v]);}}if( fa == 0 && child < 2) iscut[u] = false;return low[u];}void getbl(int n) {nb = pt = 0;while( !sg.empty() ) sg.pop();memset(dfn, 0, sizeof(dfn));memset(bln, 0, sizeof(bln));memset(iscut, 0, sizeof(iscut));int i;for(i = 1; i <= n; i++)if( !dfn[i] ) dfs(i, 0);}bool hwmatch(int u, int cnt) {int i, vn = G[u].size();for(i = 0; i < vn; i++) {int v = G[u][i];if(bln[v] != cnt) continue;if( color[u] == color[v] ) return false;if( !color[v] ) {color[v] = 3 - color[u];if( !hwmatch(v, cnt) ) return false;}}return true;}int main() {int n, m;while(~scanf("%d%d", &n ,&m), n|m) {memset(g, 0, sizeof(g));int u, v;while(m --) {scanf("%d%d", &u, &v);g[u][v] = g[v][u] = true;}int i, j;for(i = 1; i <= n; i++) G[i].clear();for(i = 1; i <= n; i++) {for(j = i + 1; j <= n; j++) {if( !g[i][j] ) {G[i].push_back(j);G[j].push_back(i);}}}getbl(n);memset(odd, 0, sizeof(odd));for(i = 1; i <= nb; i++) {memset(color, 0, sizeof(color));int vn = bl[i].size();for(j = 0; j < vn; j++) {bln[ bl[i][j] ] = i;}color[ bl[i][0] ] = 1;if( !hwmatch(bl[i][0], i) ) {for(j = 0; j < vn; j++) {odd[ bl[i][j] ] = true;}}}int ans = n;for(i = 1; i <= n; i ++) {if(odd[i]) ans --;}printf("%d\n", ans);}return 0;}
上升
- LA 3523 圆桌骑士
- LA 3523 圆桌骑士 (双连通)
- 双连通分量,二分图(圆桌骑士,LA 3523)
- UVALive 3523 圆桌骑士
- 圆桌骑士
- Josephus问题(圆桌骑士)
- poj2942 圆桌骑士
- POJ 2942 圆桌骑士问题。
- 例题5.5 圆桌骑士 LA3523
- 圆桌骑士 图的连通性
- 【图的连通性】poj2942圆桌骑士
- 以圆桌骑士为例浅尝HTML5游戏开发
- POJ 2942 圆桌骑士 点双连通+二分图判定
- 以圆桌骑士为例浅尝HTML5游戏开发
- poj2942圆桌骑士【点双连通分量+二分图判断】
- flash硕思闪客V2005便携绿色破解版圆桌骑士简体中文豪华套装
- UVa Problem 10195 The Knights of the Round Table (圆桌骑士)
- poj 2942 圆桌骑士 无向图割点 奇圈 交叉染色
- 使用数据库做缓存
- Oracle的pl/sql 编程的hello实例
- Java Web : Struts2第一个简单例子 浅解
- 关于JSONKit的使用
- C++指针探讨一
- LA 3523 圆桌骑士
- FFmpeg 开发流程
- CFLAGS
- eclipse 设置字体大小
- 安全通信系统--OpenSSL的安装编译、证书生成
- Qt4精彩实例分析笔记--各个位置信息
- javascript 事件详解
- 哈哈,来看看北京。(注:这不是一篇技术博客)
- .NET c# Color对象的使用介绍(转)