舞动的夜晚 CH Round #17

描述

L公司和H公司举办了一次联谊晚会。晚会上,L公司的N位员工和H公司的M位员工打算进行一场交际舞。在这些领导中,一些L公司的员工和H公司的员工之间是互相认识的,这样的认识关系一共有T对。舞会上,每位员工会尝试选择一名Ta认识的对方公司的员工作为舞伴,并且每位员工至多跳一支舞。完成的交际舞的数量越多,晚会的气氛就越热烈。顾及到晚会的气氛,员工们希望知道,哪些员工之间如果进行了交际舞,就会使整场晚会能够完成的交际舞的最大数量减小。

输入格式

第一行三个整数N、M、T。
接下来T行每行两个整数x、y,表示L公司的员工x和H公司的员工y互相认识。

输出格式

第一行一个整数cnt,表示进行了交际舞后会使整场晚会能够完成的交际舞的最大数量减小的员工有多少对。
第二行cnt个整数,升序输出这样的一对员工的认识关系的编号(他们的认识关系是在输入数据中读入的第几条认识关系)。如果cnt=0,输出一个空行。

样例输入

3 3 6
1 1
2 1
2 2
3 1
3 2
3 3

样例输出

3
2 4 5

数据范围与约定

  • 对于50%的数据,1<=N,M<=100,1<=T<=1000。
  • 对于100%的数据,1<=N,M<=10000,1<=T<=100000,1<=x<=N,1<=y<=M

题解:

其实我很想问,这范围是给网络流的?忽然想到,白书上有句话---可以证明,对于二分图最大匹配这样的特殊图,dinic算法的复杂度为O(sqrt(n)*m);

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

二分图的可行边/必须边: 先用Dinic求出任意一组最大匹配。 建一张新图:对于匹配边(u,v),v到u连边;非匹配边u到v连边; 对于匹配的左部点u,u到S连边;未匹配的左部点u,S到u连边; 对于匹配的右部点v,T到v连边;未匹配的右部点v,v到T连边。 用Tarjan求强连通分量,若(u,v)是匹配边或者u,v在同一个SCC中——可行边;若(u,v)是匹配边且u,v不在同一个SCC中——必须边。---lyd

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

其实后面的一大坨构图就是一句话---残量网络

直接在残量网络里tarjan,然后扫一遍即可

ps:这题教育我,即使感觉数组不会越界,也一定要把数组开大,不爆内存就好!

代码:

 const inf=maxlongint;
type node=record
from,go,next,v:longint;
end;
var tot,i,j,n,m,maxflow,l,r,s,t,ans,num,cnt,ti,top:longint;
h,head,q,cur,a,dfn,low,sta,scc,x,y:array[..] of longint;
e:array[..] of node;
b:array[..] of boolean;
function min(x,y:longint):longint;
begin
if x<y then exit(x) else exit(y);
end;
procedure ins(x,y,z:longint);
begin
inc(tot);
e[tot].from:=x;e[tot].go:=y;e[tot].v:=z;e[tot].next:=head[x];head[x]:=tot;
end;
procedure insert(x,y,z:longint);
begin
ins(x,y,z);ins(y,x,);
end;
function bfs:boolean;
var i,x,y:longint;
begin
fillchar(h,sizeof(h),);
l:=;r:=;q[]:=s;h[s]:=;
while l<r do
begin
inc(l);
x:=q[l];
i:=head[x];
while i<> do
begin
y:=e[i].go;
if (e[i].v<>) and (h[y]=) then
begin
h[y]:=h[x]+;
inc(r);q[r]:=y;
end;
i:=e[i].next;
end;
end;
exit (h[t]<>);
end;
function dfs(x,f:longint):longint;
var i,y,used,tmp:longint;
begin
if x=t then exit(f);
used:=;
i:=cur[x];
while i<> do
begin
y:=e[i].go;
if (h[y]=h[x]+) and (e[i].v<>) then
begin
tmp:=dfs(y,min(e[i].v,f-used));
dec(e[i].v,tmp);if e[i].v<> then cur[x]:=i;
inc(e[i xor ].v,tmp);
inc(used,tmp);
if used=f then exit(f);
end;
i:=e[i].next;
end;
if used= then h[x]:=-;
exit(used);
end;
procedure dinic;
begin
while bfs do
begin
for i:=s to t do cur[i]:=head[i];
inc(maxflow,dfs(s,inf));
end;
end;
procedure dfs(x:longint);
var i,y,z:longint;
begin
inc(ti);dfn[x]:=ti;low[x]:=ti;inc(top);sta[top]:=x;
i:=head[x];
while i<> do
begin
y:=e[i].go;
if e[i].v<> then
begin
if dfn[y]= then
begin
dfs(y);
low[x]:=min(low[x],low[y]);
end
else if scc[y]= then low[x]:=min(low[x],dfn[y]);
end;
i:=e[i].next;
end;
if low[x]=dfn[x] then
begin
inc(cnt);
while true do
begin
z:=sta[top];dec(top);
scc[z]:=cnt;
if z=x then break;
end;
end;
end;
procedure tarjan;
begin
ti:=;cnt:=;ti:=;
fillchar(dfn,sizeof(dfn),);
for i:=s to t do if dfn[i]= then dfs(i);
end;
procedure init;
begin
tot:=;
readln(n,m,num);
s:=;t:=n+m+;
for i:= to n do insert(s,i,);
for i:= to num do
begin
readln(x[i],y[i]);inc(y[i],n);
a[i]:=tot+;insert(x[i],y[i],);
end;
for i:=n+ to n+m do insert(i,t,);
end;
procedure main;
begin
maxflow:=;
dinic;
tarjan;
ans:=;
for i:= to num do
begin
if (e[a[i]].v<>) and (scc[x[i]]<>scc[y[i]]) then
begin
b[i]:=true;inc(ans);
end;
end;
writeln(ans);
if ans= then writeln else for i:= to num do if b[i] then write(i,' ');
end; begin
assign(input,'input.txt');assign(output,'output.txt');
reset(input);rewrite(output);
init;
main;
close(input);close(output);
end.

CH Round #17 舞动的夜晚的更多相关文章

  1. CH Round #52 还教室[线段树 方差]

    还教室 CH Round #52 - Thinking Bear #1 (NOIP模拟赛) [引子]还记得 NOIP 2012 提高组 Day2 中的借教室吗?时光飞逝,光阴荏苒,两年过去了,曾经借教 ...

  2. CH Round #72树洞[二分答案 DFS&&BFS]

    树洞 CH Round #72 - NOIP夏季划水赛 描述 在一片栖息地上有N棵树,每棵树下住着一只兔子,有M条路径连接这些树.更特殊地是,只有一棵树有3条或更多的路径与它相连,其它的树只有1条或2 ...

  3. CH Round #30 摆花[矩阵乘法]

    摆花 CH Round #30 - 清明欢乐赛 背景及描述 艺术馆门前将摆出许多花,一共有n个位置排成一排,每个位置可以摆花也可以不摆花.有些花如果摆在相邻的位置(隔着一个空的位置不算相邻),就不好看 ...

  4. contesthunter CH Round #64 - MFOI杯水题欢乐赛day1 solve

    http://www.contesthunter.org/contest/CH Round %2364 - MFOI杯水题欢乐赛 day1/Solve Solve CH Round #64 - MFO ...

  5. CH Round #45 能量释放

    能量释放 CH Round #45 - alan有一些陷阱 III 题目描述 alan得到一块由个能量晶体构成的矿石,对于矿石中的每一个能量晶体,如果用化学物质刺激某一个能量晶体,就能使它释放能量. ...

  6. CH Round #57 - Story of the OI Class 凯撒密码

    很有意思的一道题目 考场上想的是HASH成一个整数,把末位asicc码值*1,依次乘*10,得到一个整数,然后利用等差性.唯一性快排Nlogn乱搞的 证明如下: 对于明文abcde 密文 bcdef ...

  7. “玲珑杯”线上赛 Round #17 河南专场

    闲来无事呆在寝室打打题,没有想到还有中奖这种操作,超开心的 玲珑杯”线上赛 Round #17 河南专场 Start Time:2017-06-24 12:00:00 End Time:2017-06 ...

  8. Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)

    Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...

  9. Educational Codeforces Round 17

    Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...

随机推荐

  1. sublime 安装 Terminal 使用 cmder

    在 packagecontrol.io 可以找到 Terminal. 在 cmder.net 下载 cmder 复制 Terminal.sublime-settings 文件到 C:\Users\WX ...

  2. 嵌入式系统关机/Embeded System PowerOff HowTo?

    REFER: 嵌入式Linux实现关机命令 REFER: Embedded File System and power-off REFER: kernel/reboot.c REFER: PowerO ...

  3. 清橙 A1120 拦截导弹 -- 动态规划(最长上升子序列)

    题目地址:http://oj.tsinsen.com/A1120 问题描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但 ...

  4. 七牛云覆盖上传 php

    使用七牛云过程中遇到了需要上传覆盖的情况,最终解决,分享给大家. 七牛云sdk上传示例中是这样写的 <?php require_once 'path_to_sdk/vendor/autoload ...

  5. HTML5 基础

    1.HTML5 简介 HTML5 是最新的 HTML 标准,他是万维网的核心语言.标准通用标记语言下的一个应用“超文本标记语言”. HTML 的上一个标准 HTML4.01 诞生于 1999年,他的第 ...

  6. ToString()字符转换类型

    100.ToString("n");结果是100.00 100.ToString("c");结果是¥100.00 100.ToString("e&qu ...

  7. makefile的简单写法

    makefile 使用方法: vi 一个Makefile文件 CC = g++   // 指的是用什么编译器RM = rm -rf   // 定义一个删除的指令(变量)CFLAGS = -c -Wal ...

  8. C++ map映射的使用方法

    今天考试做了道题,用上了map,这是一道提高组联赛难度的题目,先发题目: ****************************** 1. A-B problem( dec.c/cpp/pas) . ...

  9. Oracle 排序分析函数之ROW_NUMBER、RANK和DENSE_RANK

    我们都知道分析函数功能很强大,可能需要写很复杂的标准SQL才能办到或不可能办到的事,使用分析函数却能很容易完成.我们经常会用到排序分析函数,如ROW_NUMBER,RANK,DENSE_RANK.这三 ...

  10. Win8.1设置窗口背景颜色为护眼色

    更改注册表 window+R --->输入regedit(点击确定后进入注册表编辑器) 需要修改以下两个地方,重启电脑生效: [HKEY_CURRENT_USER\Control Panel\C ...