题意:

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

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

分析:

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

先找出一个最大的可行流 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. Xtts v4变化&先决条件&已知问题

    V4变化的主要有:     1.这个采购使用简化的命令.源的一个命令(--backup)和目标的一个命令(--restore). 2.此过程只需要在源和目标的$ TMPDIR(res.txt)之间复制 ...

  2. GreenPlum 大数据平台--备份-邮件配置-gpcrondump & gpdbrestore(五)

    01,备份 生成备份数据库 [gpadmin@greenplum01 ~]$ gpcrondump -l /gpbackup/back2/gpcorndump.log -x postgres -v [ ...

  3. ksframework的xlua版本

    https://github.com/zhaoqingqing/KSFramework_xlua

  4. matlab实现M/M/1排队系统

    Matlab实现. 分为主函数 MyLine 和被调用函数 Func. 主函数 MyLine 实现在 Func 函数的基础上实现序贯法, 将平均等待队长作为每次模拟的 X,求出置信区间.Func 函数 ...

  5. pat02-线性结构4. Pop Sequence (25)

    02-线性结构4. Pop Sequence (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  6. nyoj1032——Save Princess——————【set应用】

    Save Princess 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Yesterday, the princess was kidnapped by a de ...

  7. js 获取 Url.Action 设置area

    var url = '@Url.Action("UserEdit","User",new { Area = "Setup", id = 1} ...

  8. 8、列表:ion-list

    1.基本样式 no-lines 属性 隐藏列表项之间的分割符 inset 属性 去掉 ion-list的 外边框. 默认 的 ion-list 是有外边框的.   /* ---示例代码----*/ & ...

  9. SQL更新派工单数量=任务数量的

    select b.FCommitQty '任务数量',a.FQty '派工数量',a.FSourceBillNo '派工单号',b.FBillNo '任务单号',a.FStatus '派工状态' fr ...

  10. SpringSecurity 3.2入门(8)自定义权限控制数据库设计

    ; -- ---------------------------- -- Table structure for t_system_authority_info -- ---------------- ...