题面


二分后用网络流判定
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的更多相关文章

  1. Luogu 3424 [POI2005]SUM-Fibonacci Sums

    Solution 没有任何算法, 只要会$for$ 就能AC... 我们观察到, 如果有一个位置 的$F_i$ 的系数$b_i$ 为2, 那么只需要把 $b_{i-2}+1,b_{i+1}+1$即可. ...

  2. Luogu 3421 [POI2005]SKO-Knights - Exgcd

    Description 给出一个骑士的 $N$种 中行走的方式 $(a_i, b_i)$, 可以使骑士的坐标$(-a,-b)$或$(+a,+b)$. 我们需要找出 第二个骑士的 两种行走方式 $(c_ ...

  3. luogu P3420 [POI2005]SKA-Piggy Banks

    题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opened with its correspon ...

  4. 【BZOJ】【1532】【POI2005】Kos-Dicing

    网络流/二分法 最大值最小……直接做不太好做的时候就可以用二分+判定来搞. 这题我们就也可以二分最大胜场v,那么怎么来判定呢?首先我们发现:每场比赛要么A赢,要么B赢,这一点跟二分图匹配非常类似,那么 ...

  5. Bzoj 1532: [POI2005]Kos-Dicing 二分,网络流

    1532: [POI2005]Kos-Dicing Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1373  Solved: 444[Submit][St ...

  6. BZOJ1532: [POI2005]Kos-Dicing

    1532: [POI2005]Kos-Dicing Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1060  Solved: 321[Submit][St ...

  7. bzoj [POI2005]Kos-Dicing 二分+网络流

    [POI2005]Kos-Dicing Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1835  Solved: 661[Submit][Status][ ...

  8. BZOJ_1532_[POI2005]Kos-Dicing_二分+网络流

    BZOJ_1532_[POI2005]Kos-Dicing_二分+网络流 Description Dicing 是一个两人玩的游戏,这个游戏在Byteotia非常流行. 甚至人们专门成立了这个游戏的一 ...

  9. 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 题意: 你打算在纸上印一串字 ...

随机推荐

  1. [Python Study Notes]异常处理

    正则表达式 python提供了两个非常重要的功能来处理python程序在运行中出现的异常和错误.你可以使用该功能来调试python程序. 异常处理 断言(Assertions) python标准异常 ...

  2. elasticsearch 6 在 centos 6 上的安装问题

    ERROR: bootstrap checks failed max file descriptors [4096] for elasticsearch process likely too low, ...

  3. neo-thinsdk-cs 之 thinWallet 接入私链

    neo-thinsdk-cs 之 thinWallet 接入私链 2017年底刚开始接触区块链,目前在被 NEO 折磨. 一开始被官方文档和 NEO-GUI 搞得体无完肤(尤其是传说中的 F12),也 ...

  4. linux下简洁优化部署tomcat应用

    本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: 本文是自己根据公司架构部署tomcat方法整理出来的文本 修 ...

  5. 【Unity3D技术文档翻译】第1.9篇 使用 Unity AssetBundle Browser tool (AssetBundle系列完结)

    上一章:[Unity3D技术文档翻译]第1.8篇 AssetBundles 问题及解决方法 本章原文所在章节:[Unity Manual]→[Working in Unity]→[Advanced D ...

  6. 【Unity3D技术文档翻译】第1.4篇 AssetBundle 依赖关系

    上一章:[Unity3D技术文档翻译]第1.3篇 创建 AssetBundles 本章原文所在章节:[Unity Manual]→[Working in Unity]→[Advanced Develo ...

  7. Python学习/复习神器-->各种方法/技巧在哪用和典型例子(一)

    就我个人在学习Python的过程中,经常会出现学习了新方法后,如果隔上几天不用,就忘了的情况,或者刚学习的更好的方法没有得到应用,还是沿用已有的方法,这样很不利于学习和掌握新姿势,从而拉长学习时间,增 ...

  8. 利用FileReader实现上传图片前本地预览

    引子 平时做图片上传预览时如果没有特殊的要求就直接先把图片传到后台去,成功之后拿到URL再渲染到页面上,这样做在图片比较小的时候没什么问题,大一点的话就会比较慢才能看到预览了,而且还产生了垃圾文件,所 ...

  9. PAT乙级 1034

    思路:是个水题,但是有坑.不能被题目忽悠了,题目保证正确的输出中没有超过整型范围的整数. 它只是保证结果不超出int,但是我们在运算过程中的乘法可能会超出int,直接把所有int改成long long ...

  10. ImportError: No module named 'xlrd' 解决办法

    import pandas as pd data = pd.read_excel('工作簿1.xls',sheetname='Sheet1') 用pandas读取Excel文件时,会提示 Import ...