就是加一个1的下界就好了。

 #include<bits/stdc++.h>
#define N 100005
#define LL long long
#define inf 0x3f3f3f3f
#define ls tr[x][0]
#define rs tr[x][1]
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
struct node{
int c,v,from,to,next;
}e[N];
int tot=,ans,from[N],n,m,S,T,head[N],cnt,dis[N],q[N<<];
bool inq[N];
void ine(int x, int y, int v, int c)
{
e[++tot].to=y; e[tot].next=head[x]; head[x]=tot;
e[tot].v=v; e[tot].c=c; e[tot].from=x;
}
void insert(int x, int y, int c, int v)
{
ine(x,y,v,c); ine(y,x,-v,);
}
bool spfa()
{
for (int i=; i<=n+; i++) dis[i]=inf;
int l=,r=; q[]=S; dis[S]=; inq[S]=;
while (l<r)
{
int x=q[l++];
for (int i=head[x];i;i=e[i].next)
if (dis[e[i].to]>dis[x]+e[i].v && e[i].c)
{
dis[e[i].to]=dis[x]+e[i].v;
from[e[i].to]=i;
if (!inq[e[i].to])
{
inq[e[i].to]=;
q[r++]=e[i].to;
}
}
inq[x]=;
}
if (dis[T]==inf) return ;
return ;
}
void mcf()
{
int x=inf;
for (int i=from[T];i;i=from[e[i].from]) x=min(x,e[i].c);
for (int i=from[T];i;i=from[e[i].from]) ans+=x*e[i].v,e[i].c-=x,e[i^].c+=x;
}
void fyl()
{
while (spfa()) mcf();
}
int main()
{
n=ra();
S=n+; T=n+;
for (int i=; i<=n; i++)
{
int cnt=ra();
insert(i,T,cnt,);
if (i!=) insert(i,,inf,);
for (int j=; j<=cnt; j++)
{
int x=ra(),v=ra();
insert(S,x,,v);
insert(i,x,inf,v);
}
}
fyl();
cout<<ans;
return ;
}

最新文章

  1. ZK 页面间参数传递
  2. MVCC PostgreSQL实现事务和多版本并发控制的精华
  3. 几个有用的JavaScript/jQuery代码片段(转)
  4. 为什么for(int i=0;i&lt;9;i++) 在c语言中是错误的?
  5. django rest_framework
  6. python 三元运算符
  7. 用Volley让GridView加载网络图片
  8. 织梦dedecms后台添加图片style全部都变成st&lt;x&gt;yle的解决办法
  9. #pragma的用法
  10. 【Tips】Endnote导入IEEE Xplore文献方法《转载》
  11. ACM/ICPM2014鞍山现场赛D Galaxy (HDU 5073)
  12. .net 报错汇总——持续更新
  13. nginx配置location总结及rewrite规则写法(2)
  14. 将自己的域名解析跳转到博客主页(GitHub中的gitpage跳转)
  15. [转CSDN多篇文章]WEB 3D SVG CAD 矢量 几种实现方案
  16. Chrome格式化JavaScript代码
  17. Expo大作战(十八)--expo如何发布成独立应用程序,打包成apk或者ipa,发布到对应应用商店
  18. Redis源码阅读(二)高可用设计——复制
  19. UEditor 的使用
  20. [Cubieboard] Node.js 在 Lubuntu 上安装指南

热门文章

  1. POI 2001 Goldmine 线段树 扫描线
  2. Windows安装OpenSSH服务
  3. 南邮CG-CTF Web记录
  4. USACO[19-20]Dec银组题解
  5. 在CentOS 7环境下安装 Spark
  6. 第3节 sqoop:5、实现数据的控制导入
  7. sql 经纬度范围检索(谷歌方案)
  8. CRC校验算法详解
  9. other#一些问题的列表
  10. Day8 - B - Non-Secret Cypher CodeForces - 190D