Luogu[POI2005]KOS-Dicing
二分后用网络流判定
S->人,流量为二分的mid
人->比赛,流量为1
比赛->T,流量为1
输出方案只要判断a就可以了
# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
# define Copy(a, b) memcpy(a, b, sizeof(a))
# define ID(a, b) n * (a - 1) + b
using namespace std;
typedef long long ll;
const int _(2e4 + 10), __(2e5 + 10), INF(2147483647);
IL ll Read(){
RG char c = getchar(); RG ll x = 0, z = 1;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int n, m, a[_], w[__], fst[_], nxt[__], to[__], cnt, S, T, lev[_], cur[_], max_flow, tmp1[_], tmp2[__], tcnt, ans[_];
queue <int> Q;
IL void Add(RG int u, RG int v, RG int f){
w[cnt] = f; to[cnt] = v; nxt[cnt] = fst[u]; fst[u] = cnt++;
w[cnt] = 0; to[cnt] = u; nxt[cnt] = fst[v]; fst[v] = cnt++;
}
IL int Dfs(RG int u, RG int maxf){
if(u == T) return maxf;
RG int ret = 0;
for(RG int &e = cur[u]; e != -1; e = nxt[e]){
if(lev[to[e]] != lev[u] + 1 || !w[e]) continue;
RG int f = Dfs(to[e], min(w[e], maxf - ret));
ret += f; w[e ^ 1] += f; w[e] -= f;
if(ret == maxf) break;
}
if(!ret) lev[u] = 0;
return ret;
}
IL bool Bfs(){
Fill(lev, 0); lev[S] = 1; Q.push(S);
while(!Q.empty()){
RG int u = Q.front(); Q.pop();
for(RG int e = fst[u]; e != -1; e = nxt[e]){
if(lev[to[e]] || !w[e]) continue;
lev[to[e]] = lev[u] + 1;
Q.push(to[e]);
}
}
return lev[T];
}
IL void Getans(){
for(RG int i = 1; i <= m; i++)
for(RG int e = fst[i + n]; e != -1; e = nxt[e])
if(to[e] && to[e] <= n && w[e]){
if(to[e] == a[i]) ans[i] = 1;
else ans[i] = 0;
}
}
IL bool Check(RG int x){
Copy(fst, tmp1); Copy(w, tmp2); cnt = tcnt;
for(RG int i = 1; i <= n; i++) Add(S, i, x);
for(max_flow = 0; Bfs(); ) Copy(cur, fst), max_flow += Dfs(S, INF);
return max_flow == m;
}
int main(RG int argc, RG char* argv[]){
Fill(fst, -1); n = Read(); m = Read(); T = n + m + 1;
for(RG int i = 1, b; i <= m; i++){
a[i] = Read(), b = Read();
Add(a[i], i + n, 1); Add(b, i + n, 1); Add(i + n, T, 1);
}
Copy(tmp1, fst); Copy(tmp2, w); tcnt = cnt;
RG int l = 1, r = m, num = 0;
while(l <= r){
RG int mid = (l + r) >> 1;
if(Check(mid)) r = mid - 1, num = mid, Getans();
else l = mid + 1;
}
printf("%d\n", num);
for(RG int i = 1; i <= m; i++) printf("%d\n", ans[i]);
return 0;
}
Luogu[POI2005]KOS-Dicing的更多相关文章
- Luogu 3424 [POI2005]SUM-Fibonacci Sums
Solution 没有任何算法, 只要会$for$ 就能AC... 我们观察到, 如果有一个位置 的$F_i$ 的系数$b_i$ 为2, 那么只需要把 $b_{i-2}+1,b_{i+1}+1$即可. ...
- Luogu 3421 [POI2005]SKO-Knights - Exgcd
Description 给出一个骑士的 $N$种 中行走的方式 $(a_i, b_i)$, 可以使骑士的坐标$(-a,-b)$或$(+a,+b)$. 我们需要找出 第二个骑士的 两种行走方式 $(c_ ...
- luogu P3420 [POI2005]SKA-Piggy Banks
题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opened with its correspon ...
- 【BZOJ】【1532】【POI2005】Kos-Dicing
网络流/二分法 最大值最小……直接做不太好做的时候就可以用二分+判定来搞. 这题我们就也可以二分最大胜场v,那么怎么来判定呢?首先我们发现:每场比赛要么A赢,要么B赢,这一点跟二分图匹配非常类似,那么 ...
- Bzoj 1532: [POI2005]Kos-Dicing 二分,网络流
1532: [POI2005]Kos-Dicing Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1373 Solved: 444[Submit][St ...
- BZOJ1532: [POI2005]Kos-Dicing
1532: [POI2005]Kos-Dicing Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1060 Solved: 321[Submit][St ...
- bzoj [POI2005]Kos-Dicing 二分+网络流
[POI2005]Kos-Dicing Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1835 Solved: 661[Submit][Status][ ...
- BZOJ_1532_[POI2005]Kos-Dicing_二分+网络流
BZOJ_1532_[POI2005]Kos-Dicing_二分+网络流 Description Dicing 是一个两人玩的游戏,这个游戏在Byteotia非常流行. 甚至人们专门成立了这个游戏的一 ...
- 2021.11.09 P3426 [POI2005]SZA-Template(KMP+DP)
2021.11.09 P3426 [POI2005]SZA-Template(KMP+DP) https://www.luogu.com.cn/problem/P3426 题意: 你打算在纸上印一串字 ...
随机推荐
- Nginx与Tomcat/PHP架构优化的技术分享
PHP性能优化 一般我们是在/usr/local/php5/etc/php-fpm.conf这个文件里面进行相应的配置. 1) 如果设置成static,php-fpm进程数自始至终都是pm ...
- css里面如何设置body背景图片满屏
@{ Layout = null; ViewBag.Title = "Login Page";} <!DOCTYPE html> <html>& ...
- 【HTTP协议】---HTTPS协议
HTTPS协议 一.为什么需要https 1.HTTP是明文传输的,也就意味着,介于发送端.接收端中间的任意节点都可以知道你们传输的内容是什么.这些节点可能是路由器.代理等. 举个最常见的例子,用户登 ...
- Linux-PATH_环境变量
PATH变量 是linux系统里的一个环境变量,系统已经定义好了,我们不需要再定义. 作用: 是linux里使用的命令都存在在PATH变量后面指定的目录下,我们使用命令 ...
- bzoj 2120 带修改莫队
2120: 数颜色 Time Limit: 6 Sec Memory Limit: 259 MBSubmit: 7340 Solved: 2982[Submit][Status][Discuss] ...
- js使用defineProperty的一些坑
var p2={ }; Object.defineProperty(p2,"gs",{ get:function () { return this.gs; }, set:funct ...
- qt 如何安装 Debuggers 调试器 ?
1.下载 SDK 或 WDK 打开网址:https://developer.microsoft.com/zh-cn/windows/hardware/windows-driver-kit 选择 SDK ...
- 《android开发艺术探索》读书笔记(四)--View工作原理
接上篇<android开发艺术探索>读书笔记(三) No1: View的三大流程:测量流程.布局流程.绘制流程 No2: ViewRoot对应于ViewRootImpl类,它是连接Wind ...
- java:条件表达式
if (results.length() == 0) { return ""; } else { return results.substring(0, results.lengt ...
- sqoop:mysql和Hbase/Hive/Hdfs之间相互导入数据
1.安装sqoop 请参考http://www.cnblogs.com/Richardzhu/p/3322635.html 增加了SQOOP_HOME相关环境变量:source ~/.bashrc ...