博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bzoj1854: [Scoi2010]游戏
阅读量:4631 次
发布时间:2019-06-09

本文共 1123 字,大约阅读时间需要 3 分钟。

可以跑二分图

到第一个不能匹配的点就退出

嗯 还有并查集判环的做法?

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 8 using namespace std; 9 10 void setIO(const string& a) {11 freopen((a+".in").c_str(), "r", stdin);12 freopen((a+".out").c_str(), "w", stdout);13 }14 15 const int N = 1000000 + 10, M = 10000 + 10;16 17 #include
18 vector
G[M];19 int mat[M];20 21 void AddEdge(int u, int v) {22 G[u].push_back(v);23 }24 25 int vis[N], clk;26 27 bool find(int u) {28 for(unsigned i = 0; i < G[u].size(); i++) {29 int v = G[u][i];30 if(vis[v] != clk) {31 vis[v] = clk;32 if(mat[v] == 0 || find(mat[v])) {33 mat[v] = u;34 return 1;35 }36 }37 }38 return 0;39 }40 41 int work(int n) {42 for(int i = 1; i <= n; i++) {43 ++clk;44 if(!find(i)) return i - 1;45 }46 return n;47 }48 49 int main() {50 int x, y, n;51 scanf("%d", &n);52 for(int i = 1; i <= n; i++) {53 scanf("%d%d", &x, &y);54 AddEdge(x, i);55 AddEdge(y, i);56 }57 printf("%d\n", work(n));58 59 return 0;60 }

 

转载于:https://www.cnblogs.com/showson/p/5006531.html

你可能感兴趣的文章
Java 的zip压缩和解压缩
查看>>
SPOJ375(树链剖分)
查看>>
C基础知识小总结(十)
查看>>
Ignatius and the Princess IV (水题)
查看>>
ConcurrentHashMap实现原理及源码分析
查看>>
oracle执行计划连接方式
查看>>
机器学习 决策树 ID3
查看>>
Cmake
查看>>
vue 之 nextTick 与$nextTick
查看>>
JS设计模式——3.封装与信息隐藏
查看>>
git-- 使用
查看>>
delphi对窗体的查询(delphi xe2)
查看>>
Ajax跨域:Jsonp原理解析
查看>>
hdu 5099 Comparison of Android versions 枚举题意
查看>>
算法第二章上机实践报告
查看>>
linux--memcache的安装和使用(转)
查看>>
有关于Matlab的regionprops函数的PixelIdxList和PixelList的一点解释
查看>>
Event Loop
查看>>
new做了些什么?
查看>>
BZOJ3835[Poi2014]Supercomputer——斜率优化
查看>>