题意:

用最少的路径,覆盖掉所有的边,(点可以重复);

不是用最小路径覆盖,最小路径覆盖是覆盖点;

分析:

建图:入度<出度,说明这是个起点,从这里出发,入度>出度,说明从这里结束;

先找出一个最大的可行流 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的更多相关文章

  1. Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )

    题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...

  2. 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 ...

  3. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  4. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  5. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  6. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  7. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  8. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  9. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

随机推荐

  1. JAVA实体类不要使用基本类型,基本类型包含byte、int、short、long、float、double、char、boolean

    由于JAVA的基本类型会有默认值,例如当某个类中存在private  int age;字段时,创建这个类时,age会有默认值0.当使用age属性时,它总会有值.因此在某些情况下,便无法实现age为nu ...

  2. 网络编程api bind函数细节 select 细节

    struct sockaddr_in bindaddr; bindaddr.sin_family = AF_INET; bindaddr.sin_addr.s_addr = htonl(INADDR_ ...

  3. 数据库nomount mount open阶段走向

    先来简要了解一下Oracle数据库体系架构以便于后面深入理解,Oracle Server主要由实例(instance)和数据库(database)组成.实例(instance)由共享内存(SGA)和后 ...

  4. 日志收集之filebeat

    一,软件介绍 Filebeat是一个轻量级日志传输Agent,可以将指定日志转发到Logstash.Elasticsearch.Kafka.Redis等中.Filebeat占用资源少,而且安装配置也比 ...

  5. 使用Redis 配置替换fastjson 反序列化报错 com.alibaba.fastjson.JSONException: autoType is not support

    新建的GenericFastJson2JsonRedisSerializer里面添加白名 添加: static {        ParserConfig.getGlobalInstance().ad ...

  6. 记录: Win10+Ubuntu18.04双系统安装

    在重装windows系统的时候顺便将ubuntu也重装了. window 10 安装 制作USB启动盘 到"微软中国下载中心"(http://www.microsoft.com/z ...

  7. [Scala] Currying

    Currying是一種函數式編程技巧, 指的是把接受多個參數的函數變換成接受一個單一參數的函數. 以一個簡單的例子在Scala中實現.. def f(a:Int, b:Int)={ a+b } //f ...

  8. 白话SpringCloud | 第四章:服务消费者(RestTemple+Ribbon+Feign)

    前言 上两章节,介绍了下关于注册中心-Eureka的使用及高可用的配置示例,本章节开始,来介绍下服务和服务之间如何进行服务调用的,同时会讲解下几种不同方式的服务调用. 一点知识 何为负载均衡 实现的方 ...

  9. pycharm激活码------2017.11.之前有效

    BIG3CLIK6F-eyJsaWNlbnNlSWQiOiJCSUczQ0xJSzZGIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...

  10. SQL中CASE 的用法 转载

    sql语言中有没有类似C语言中的switch case的语句?? 没有,用case   when   来代替就行了.              例如,下面的语句显示中文年月 select getdat ...