Gym 101308I Inspection
题意:
用最少的路径,覆盖掉所有的边,(点可以重复);
不是用最小路径覆盖,最小路径覆盖是覆盖点;
分析:
建图:入度<出度,说明这是个起点,从这里出发,入度>出度,说明从这里结束;
先找出一个最大的可行流 f,反着求一遍最大流fmax ,就是最小的可行流了;
输出路径这么变态的东西,我就不会了;这个题目太恶心了;
#include <bits/stdc++.h> using namespace std; const int maxn = + ;
const int inf = 0x3f3f3f3f; struct Edge {
int from,to,cap,flow;
}; struct Dinic {
int n,m,s,t;
vector<Edge> edges;
vector<int> G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn]; void init() {
edges.clear();
for(int i=; i<maxn; i++)
G[i].clear();
} void AddEdge(int from,int to,int cap) {
edges.push_back((Edge) {
from,to,cap,
});
edges.push_back((Edge) {
from,to,,
});
m = edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
} bool BFS() {
memset(vis,,sizeof(vis));
queue<int> Q;
Q.push(s);
d[s] = ;
vis[s] = ;
while(!Q.empty()) {
int x = Q.front();
Q.pop();
for(int i=; i<G[x].size(); i++) {
Edge& e = edges[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow) {
vis[e.to] = ;
d[e.to] = d[x] + ;
Q.push(e.to);
}
} }
return vis[t];
} int DFS(int x,int a) {
if(x==t||a==) return a;
int flow = ,f;
for(int& i=cur[x]; i<G[x].size(); i++) {
Edge& e = edges[G[x][i]];
if(d[x]+==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>) {
e.flow +=f;
edges[G[x][i]^].flow -=f;
flow+=f;
a-=f;
if(a==) break;
}
}
return flow;
} int Maxflow(int s,int t) {
this->s = s;
this->t = t;
int flow = ;
while(BFS()) {
memset(cur,,sizeof(cur));
flow+=DFS(s,inf);
}
return flow;
} // int dfs(int u) {
// if(u==t) return 1;
// for(int i=0; i<G[u].size(); i++) {
// Edge& e = edges[G[u][i]^1];
// if(!e.cap) continue;
// e.cap--;
// if(u!=s) putchar(' ');
// if(e.to!=t) printf("%d",e.to);
// return dfs(e.to);
// }
// return 0;
// } } sol; int d[maxn];
int n;
int ans; int s,t; int main() {
while(scanf("%d",&n)!=EOF) {
memset(d,,sizeof(d));
ans = ;
sol.init();
for(int i=; i<=n; i++) {
int k;
scanf("%d",&k);
int to;
for(int j=; j<k; j++) {
scanf("%d",&to);
to;
d[to]++;
d[i]--;
sol.AddEdge(i,to,inf);
}
} s = ,t=n+;
for(int i=; i<n; i++) {
if(d[i]<) {
sol.AddEdge(s,i,-d[i]);
ans-=d[i];
} else if(d[i]>)
sol.AddEdge(i,t,d[i]);
} ans-=sol.Maxflow(t,s); //反向最大流
printf("%d\n",ans); }
return ;
}
Gym 101308I Inspection的更多相关文章
- Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )
题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
随机推荐
- MySQL Flashback 闪回功能详解
1. 简介 mysqlbinlog flashback(闪回)用于快速恢复由于误操作丢失的数据.在DBA误操作时,可以把数据库恢复到以前某个时间点(或者说某个binlog的某个pos).比如忘了带wh ...
- Gradle发布项目到 maven 之novoda/bintray-release(3)
novoda/bintray-release 使用这个插件上传比较简单,只需要两步就可以 1.在项目根目录下的 build.gradle 添加插件依赖 // Top-level build file ...
- Fedora中安装VLC播放器
需要在机器上安装VLC,无奈不能直接通过yum安装,网上搜了一下,直接安装成功,其实挺简单的: 我的机器是Fedora15,其他的类似: ------------------------- 首先:su ...
- 使用 Ninject
在[ASP.NET MVC 小牛之路]系列上一篇文章(依赖注入(DI)和Ninject)的末尾提到了在ASP.NET MVC中使用Ninject要做的两件事情,续这篇文章之后,本文将用一个实际的示例来 ...
- (转)Python之文件读写
Python之文件读写 原文:https://www.cnblogs.com/huilixieqi/p/6494891.html 本节内容: I/O操作概述 文件读写实现原理与操作步骤 文件打开模式 ...
- 东拼西凑 vim配置-更新
"============================================================= "========================== ...
- ife task0003学习笔记(四):JavaScript构造函数
JavaScript创建对象主要是3种方法:工厂模式.构造函数模式.原型模式.其实对于构造函数的概念,我们并不陌生.在之前学习c++语言的时候,也有提到过构造函数的概念.除了创建对象,构造函数(con ...
- 分布式环境Tomcat多节点集群下共享目录配置,tomcat虚拟目录+nfs
我们可能有这种场景: 集群环境下,多个web容器需要请求一个共享目录下的文件,比如保存图片或者录音文件,任意一个节点保存后其他节点需要及时获取,此时就需要目录进行同步了,否则Nginx负载到任意一个节 ...
- WinSock 完成端口模型
之前写了关于Winsock的重叠IO模型,按理来说重叠IO模型与之前的模型相比,它的socket即是非阻塞的,也是异步的,它基本上性能非常高,但是它主要的缺点在于,即使我们使用历程来处理完成通知,但是 ...
- Android 多个activity之间的共享数据
最近打算做一个时间助手,一个service监听课表信息.课表信息可以通过另外的activity来设置,所以这里就涉及到了数据的同步问题.我设置后的信息必须同步到监听的信息去. 在java中我们用全局变 ...