2944.   Mussy Paper


Time Limit: 2.0 Seconds   Memory Limit: 65536K    Special Judge
Total Runs: 381   Accepted Runs: 98

A good mathematical joke is better, and better mathematics, 
than a dozen mediocre papers.
--J E Littlewood

RoBa, an undergraduate student, is preparing for his thesis. He collects many papers about artificial intelligence, the field that he is very interested in. However, he doesn't know how to start his work. You know at the tail of every paper, there is a list of reference papers, describing the relative work of other researchers. So these papers may form a very complicated net. Now, RoBa turns to you for help.

RoBa has given every paper an interesting value (which can be negative). A greater value indicates a more interesting paper. He wants to select a paper set S, such that, for every paper in this set, all the papers in its reference list are also contained in the set S. And what's more, he wants to make the sum of all the interesting value in the set maximum.

Input

There are multiple test cases in the input. The first line of each test case contains an integer N,(N ≤ 100) indicating the amount of papers. Then N lines followed. Each line contains two integers Vi (|Vi| ≤ 10,000) and Pi at first. Vi indicating the interesting value of the i-th paper, Pi indicating the amount of reference papers of the i-th paper. Then Pi numbers followed, indicating all the reference papers. The papers are numbered from 1 to N.

The input is terminated with N = 0.

Output

If the maximum possible sum is greater than zero, output two lines for each test case. The first line contains two integers, the maximum sum of interesting value, and the amount of papers in the selected set. The next line contains all the papers, separated by space. If there are more than one valid set to get the maximum sum, anyone will be OK. Please note the set cannot be empty.

If the maximum possible sum is no more than zero, you should only output one line says "Refused" instead, which means RoBa will refuse to do this research.

Sample Input

4
-10 1 2
10 2 3 4
-3 0
-3 0
4
-10 1 2
-10 2 3 4
-3 0
-3 0
0

Sample Output

4 3
2 3 4
Refused

Problem Setter: RoBa

Note: Special judge problem, you may get "Wrong Answer" when output in wrong format.

Source: TJU Team Selection Contest 2008 (4)

解题:最大权闭合子图

 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const int INF = ~0U>>;
struct arc {
int to,flow,next;
arc(int x = ,int y = ,int z = -) {
to = x;
flow = y;
next = z;
}
} e[maxn*maxn];
int head[maxn],gap[maxn],d[maxn],tot,S,T;
void add(int u,int v,int flow) {
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
int dfs(int u,int low) {
if(u == T) return low;
int tmp = ,minH = T - ;
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].flow) {
if(d[u] == d[e[i].to] + ) {
int a = dfs(e[i].to,min(e[i].flow,low));
e[i].flow -= a;
e[i^].flow += a;
tmp += a;
low -= a;
}
if(e[i].flow) minH = min(minH,d[e[i].to]);
if(!low) break;
}
}
if(!tmp) {
if(--gap[d[u]] == ) d[S] = T;
++gap[d[u] = minH + ];
}
return tmp;
}
int sap() {
memset(gap,,sizeof gap);
memset(d,,sizeof d);
gap[S] = T;
int ret = ;
while(d[S] < T) ret += dfs(S,INF);
return ret;
}
int n,m;
bool vis[maxn];
vector<int>ans;
void dfs(int u){
vis[u] = true;
if(u != S && u != T) ans.push_back(u);
for(int i = head[u]; ~i; i = e[i].next)
if(!vis[e[i].to] && e[i].flow) dfs(e[i].to);
} int main() {
while(scanf("%d",&n),n) {
memset(head,-,sizeof head);
S = n + ;
T = S + ;
int sum = tot = ,w;
for(int u = ,v; u <= n; ++u) {
scanf("%d%d",&w,&m);
if(w > ) {
add(S,u,w);
sum += w;
} else add(u,T,-w);
while(m--) {
scanf("%d",&v);
add(u,v,INF);
}
}
sum -= sap();
if(!sum) puts("Refused");
else{
ans.clear();
memset(vis,false,sizeof vis);
dfs(S);
printf("%d %d\n",sum,ans.size());
sort(ans.rbegin(),ans.rend());
for(int i = ans.size()-; i >= ; --i)
printf("%d%c",ans[i],i?' ':'\n');
}
}
return ;
}

TOJ 2944 Mussy Paper的更多相关文章

  1. TJU 2944 Mussy Paper 最大权闭合子图

    传送门 给你一些东西,  每个东西有一个值,有正有负. 在给一些关系, 选了其中一个物品, 和他有关系的也必须全都选上, 关系是单向的. 问最后的最大价值是多少, 如果小于0输出“   **** ”( ...

  2. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  3. TOJ 2541: Paper Cutting

    2541: Paper Cutting  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal Submit: ...

  4. 激光打印机的Color/paper, Xerography介绍

    Color Basic 看见色彩三要素: 光源,物体,视觉 加色色彩模型:R,G,B 多用于显示器 减色色彩模型:C,M,Y,K 多用于打印复印 Paper 东亚地区常用A系列标准用纸,在多功能一体机 ...

  5. Facebook Paper使用的第三方库

    Facebook Paper使用的第三方库 第三方库名 简介 链接 ACE code editor https://github.com/ajaxorg/ace Appirater 用户评分组件 ht ...

  6. paper 118:计算机视觉、模式识别、机器学习常用牛人主页链接

    牛人主页(主页有很多论文代码) Serge Belongie at UC San Diego Antonio Torralba at MIT Alexei Ffros at CMU Ce Liu at ...

  7. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  8. #Deep Learning回顾#之2006年的Science Paper

    大家都清楚神经网络在上个世纪七八十年代是着实火过一回的,尤其是后向传播BP算法出来之后,但90年代后被SVM之类抢了风头,再后来大家更熟悉的是SVM.AdaBoost.随机森林.GBDT.LR.FTR ...

  9. Tips for writing a paper

    Tips for writing a paper 1. Tips for Paper Writing 2.• Before you write a paper • When you are writi ...

随机推荐

  1. 关于web中的路径

    做了许多Demo发现,浏览器解析的路径和服务器解析的路径是不同的.我们知道,路径加上/的时候,表示的是绝对路径的意思,而如果是服务器解析的话,这个/相对的是我们的web应用,即相对于http://19 ...

  2. AJPFX总结之Socket编程

    一.Socket简介 Socket是进程通讯的一种方式,即调用这个网络库的一些API函数实现分布在不同主机的相关进程之间的数据交换. 几个定义: (1)IP地址:即依照TCP/IP协议分配给本地主机的 ...

  3. day02 -操作系统及python入门

    操作系统 1.什么是操作系统? 操作系统位于计算机硬件和应用软件之间. 是一个协调.控制.管理计算机硬件资源和软件资源的控制程序. 2.为何要有操作系统? ①·控制硬件 ②·把对硬件的复杂的操作封装成 ...

  4. java实现课堂随机点名小程序

    通过jdbc连接数据库实现读取学生花名册进行随机点名! ~jdbc连接mysql数据库  ||  注释部分代码可通过读取.txt文档实现显示学生信息 ~通过点击开始按钮实现界面中间标签不断更新学生信息 ...

  5. 探究SQL添加非聚集索引,性能提高几十倍之谜

    上周,技术支持反映:客户的一个查询操作需要耗时6.1min左右,在跟进代码后,简化了数据库的查询后仍然收效甚微.后来,技术总监分析了sql后,给其中的一个表添加的一个非聚集索引(三个字段)后,同样的查 ...

  6. laravel核心思想

    服务容器.依赖注入.门脸模式 服务容器 容器概念 用来装一个个实例的对象,比如邮件类. IOC控制反转 IOC(Inversion of Control)控制反转,面向对象,可降低代码之间的耦合度,借 ...

  7. SQL Server中的事务日志管理的阶梯,级别1:事务日志概述

    SQL Server中的事务日志管理的阶梯,级别1:事务日志概述 翻译:刘琼滨 谢雪妮 许雅莉 赖慧芳 级别1:事务日志概述 事务日志是一个文件,其中SQL服务器存储了所有与日志文件关联的数据库执行的 ...

  8. 再遇BGP

    第一次遇到BGP,是在大学的课堂上,现在再次看到它,有种深深的无奈,我只记得它的名字,忘记了它的样子. 那么什么是BGP呢? 翻译过来就是边界网关协议,一个用来网络数据进行选路的路由协议,使用TCP协 ...

  9. jeecms标签

    .@cms_content_list--新闻单页 [@cms_content channelId=' dateFormat='MM-dd' ] [#if tag_list?size>0] < ...

  10. COM(Component Object Model)接口定义

    a COM interface is defined using a language called Interface Definition Language (IDL). The IDL file ...