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 ...
随机推荐
- 案例40-层与层之间的解耦(面向接口编程)BeanFactory
1 bean.xml配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans> <!- ...
- IBM Rational Appscan: Part 2 ---reference
http://resources.infosecinstitute.com/appscan-part-2/ By Rohit T|August 16th, 2012 ----------------- ...
- Windows 下推荐软件
神器 Dism++ Quicker(效率工具) Bandizip 火绒安全软件 Everyting(搜索神器并支持http远程连接) Xmanager VMware Workstation IDMan ...
- HRBUST 1909——理工门外的树——————【离线处理,差分前缀和】
理工门外的树 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %lld , %llu Java class n ...
- BNU4286——Adjacent Bit Counts——————【dp】
Adjacent Bit Counts Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Jav ...
- Java自定义注解源码+原理解释(使用Java自定义注解校验bean传入参数合法性)
Java自定义注解源码+原理解释(使用Java自定义注解校验bean传入参数合法性) 前言:由于前段时间忙于写接口,在接口中需要做很多的参数校验,本着简洁.高效的原则,便写了这个小工具供自己使用(内容 ...
- BulletedList用途
1.用作最普通的信息显示(列表方式) 2.制作导航条 BulletedList3中模式 1.Text 文本 2.HyperLink 连接 2.LinkButton 按钮 BulletedList 导航 ...
- 动作方法中 参数,Json
一.方法中可以出现的参数类 1.HttpServletRequest 2.HttpServletResponse 3.HttpSession 4.Model 二.返回接收json数据 1. 接收,返回 ...
- (二)HTML中的部分标签
HTML作为一种超文本标记语言,其中用到了大量的标签,昨天主要看了HTML中的图像标签和表格标签. (一)图像标签 <img> <img src="url"/&g ...
- javaSE练习2——流程控制_2.1
一.企业发放的奖金根据利润提成.利润低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%:20万到40万之间时,高 ...