【BZOJ】1854: [Scoi2010]游戏【二分图】
1854: [Scoi2010]游戏
Time Limit: 5 Sec Memory Limit: 162 MB
Submit: 6759 Solved: 2812
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2
3 2
4 5
Sample Output
HINT
【数据范围】
对于30%的数据,保证N < =1000
对于100%的数据,保证N < =1000000
Solution
一开始想二分图是在属性之间连边,发现根本不可做啊!
然而正解非常巧妙了!在属性和武器之间连边,每次按顺序去看属性是否可以找到匹配(因为每个武器只能用一次),直到找不到匹配即可。
Code
#include<bits/stdc++.h>
using namespace std; int n; struct Node {
int v, nex;
} Edge[]; int stot, h[];
void add(int u, int v) {
Edge[++stot] = (Node) {v, h[u]};
h[u] = stot;
} int vis[], to[], idc;
bool find(int u) {
for(int i = h[u]; i; i = Edge[i].nex) {
int v = Edge[i].v;
if(vis[v] != idc) {
vis[v] = idc;
if(!to[v] || find(to[v])) {
to[v] = u;
return ;
}
}
}
return ;
} int main() {
scanf("%d", &n);
for(int i = ; i <= n; i ++) {
int x, y;
scanf("%d%d", &x, &y);
add(x, i); add(y, i);
}
int i;
for(i = ; i <= ; i ++) {
++ idc;
if(!find(i)) break;
}
printf("%d", i - );
return ;
}
【BZOJ】1854: [Scoi2010]游戏【二分图】的更多相关文章
- BZOJ 1854: [Scoi2010]游戏( 二分图最大匹配 )
匈牙利算法..从1~10000依次找增广路, 找不到就停止, 输出答案. --------------------------------------------------------------- ...
- BZOJ 1854: [Scoi2010]游戏 无向图判环
题目链接: 题目 1854: [Scoi2010]游戏 Time Limit: 5 Sec Memory Limit: 162 MB 问题描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装 ...
- BZOJ 1854: [Scoi2010]游戏 并查集
1854: [Scoi2010]游戏 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 2672 Solved: 958[Submit][Status][ ...
- bzoj 1854: [Scoi2010]游戏 (并查集||二分图最大匹配)
链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1854 写法1: 二分图最大匹配 思路: 将武器的属性对武器编号建边,因为只有10000种 ...
- BZOJ 1854: [Scoi2010]游戏(二分图匹配/并查集)
题面: https://www.lydsy.com/JudgeOnline/problem.php?id=1854 题解: 1.二分图匹配: 首先我们发现每件装备只能在两种属性中选一种.因此,我们以每 ...
- BZOJ 1854: [Scoi2010]游戏 [连通分量 | 并查集 | 二分图匹配]
题意: 有$n \le 10^6$中物品,每种两个权值$\le 10^4$只能选一个,使得选出的所有权值从1递增,最大递增到多少 一开始想了一个奇怪的规定流量网络流+二分答案做法...然而我还不知道怎 ...
- ●BZOJ 1854 [Scoi2010]游戏
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1854 题解: 并查集(还可以用匈牙利算法进行单路增广的二分图匹配) 把每个武器看成是一条边, ...
- bzoj 1854: [Scoi2010]游戏
#include<cstdio> #include<iostream> #include<cstring> #define M 2000008 using name ...
- bzoj 1854: [Scoi2010]游戏【匈牙利算法】
没啥可说的,就是一边属性一边道具建二分图,把两个属性都连到道具上,然后枚举匹配,如果无法匹配就输出,时间戳优化 #include<iostream> #include<cstdio& ...
随机推荐
- angular模块
深入浅析AngularJS中的模块 模块是AngularJS应用程序的一个组成部分,模块可以是一个Controller.Service服务.Filter过滤器.directive指令,这些都属于模块. ...
- bzoj千题计划269:bzoj2655: calc (拉格朗日插值)
http://www.lydsy.com/JudgeOnline/problem.php?id=2655 f[i][j] 表示[1,i]里选严格递增的j个数,序列值之和 那么ans=f[A][n] * ...
- c#的委托用法delegate
- [转载]Web API OData Inlinecount not working
http://stackoverflow.com/questions/15422831/web-api-odata-inlinecount-not-working
- json转化数组
//json格式数据 $data = '[{ "F_ModuleId": "1", "F_ParentId": "0", ...
- CodeForces 1059C
Description Let's call the following process a transformation of a sequence of length nn . If the se ...
- c++刷题(39/100)笔试题3
题目1: 现在你需要用一台奇怪的打字机书写一封书信.信的每行只能容纳宽度为100的字符,也就是说如果写下某个字符会导致行宽超过100,那么就要另起一行书写 信的内容由a-z的26个小写字母构成,而每个 ...
- 转载 为什么print在Python 3中变成了函数?
转载自编程派http://codingpy.com/article/why-print-became-a-function-in-python-3/ 原作者:Brett Cannon 原文链接:htt ...
- (F. MST Unification)最小生成树
题目链接:http://codeforces.com/contest/1108/problem/F 题目大意:给你n个点和m条边,然后让你进行一些操作使得这个图的最小生成树唯一,每次的操作是给某一条边 ...
- CSS text系列
text-shadow 语法规则: h-shadow(必需,水平阴影的位置,可负): v-shadow(必需,垂直阴影的位置,可负): blur(可选,模糊距离): color(可选,阴影的颜色). ...