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 ...
随机推荐
- Ignite cahce 存储object类型数据和object类型数据序列化后string存储区别
Ignite cache在存储时 object类型的数据和 序列化该object成string类型 两者存储时间差不多. 但是这两者在读取出来的时候,string类型比object类型快很多. 以下为 ...
- 03-struts2获得servetAPI
1 原理 三个域合一的时候相同的键值对以小的域为准.ActionContext 对象创建:每次请求的时候都会创建一个与请求对应的 ActionContext 对象.ActionContext 销毁:请 ...
- SVN创建资源库和远程连接配置
SVN创建资源库和远程连接配置 本机安装的是TortoiseSVN-1.7.5.22551-win32-svn-1.7.3.msi 安装好后会在鼠标右键中出现如图最后两项的选项: 创建svn资源库: ...
- 我的博客已经迁移到csdn
博客已经迁移csdnhttp://blog.csdn.net/u013372900 博客园我很喜欢是源于他的可扩展性,可以自己去改,但遗憾的是博客园的速度似乎不是很给力.IT能有今天的 发展是源于无数 ...
- s中的闭包
今天看了关于js闭包方面的文章,还是有些云里雾里,对于一个菜鸟来说,学习闭包确实有一定的难度,不说别的,能够在网上找到一篇优秀的是那样的不易. 当然之所以闭包难理解,个人觉得是基础知识掌握的不牢,因为 ...
- .net编程知识点
一.编程思想 OOP(面向对象) 面向对象三大特性(多态如何体现)及五项原则 AOP(面向切面编程) 面向切面编程静态植入和动态植入 二.c#23种设计模式 三.Castle是针对.NET平台的一个开 ...
- c#.net常见字符串处理方法
1.字符串比较 字符串.ComparTo(目标字符串) "a".ComparTo("b"); 2.查找子串 字符串.IndexOf(子串,查找其实位置) ; 字 ...
- 利用ajax短轮询+php与服务器交互制作简易即时聊天网站
主流的Web端即时通讯方案大致有4种:传统Ajax短轮询.Comet技术.WebSocket技术.SSE(Server-sent Events). 本文主要介绍ajax短轮询的简易实现方式. 看懂此文 ...
- python dict list tuple
Dict 创建 somedict = {} somedict = {"key": value} a = dict(one=1, two=2, three=3) c = dict(z ...
- 关于easyui 圆角按钮在ie9不能隐藏
(一)在easyui框架里 在a标签里添加class='easyui-linkbutton' 如: (二)问题:在ie9里圆角背景overflow:hidden 不起作用 (a)框架内 html 部分 ...