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. sh 脚本报错

    sh 脚本报错 思路如下: 1.建议按照手工方式运行该脚本. 2.加入-x 方式查看脚本的输出.

  2. hash系列集合的性能优化

    hash系列的集合: HashSet.LinkedHashSet     采用hash算法决定元素在集合中的存储位置 HashMap.LinkedHashMap.Hashtable   采用hash算 ...

  3. map,reduce高阶函数

    iterator:迭代器 python的iterator是一个惰性序列(即你不主动去遍历它,他不会去计算其中元素的值) m是一个iterator,所以通过tuple()函数让整个序列计算出来,并返回一 ...

  4. VPS环境配置预备篇

    VPS买到手了,在配置环境前要做哪些操作呢?老谢说一下自己的习惯,希望对和老谢一样的菜鸟有帮助更新系统内核和rpm包#安装yum-fastestmirror插件yum -y install yum-f ...

  5. sql查询作业执行时间

    SELECT  j.name                        AS Job_Name        ,        h.step_id                     AS S ...

  6. 在SQLServer使用触发器实现数据完整性

    1.实现数据完整性的手段 在sqlserver中,在服务器端实现数据完整性主要有两种手段:一种是在创建表时定义数据完整性,主要分为:实体完整性.域完整性.和级联参照完整性:实现的手段是创建主键约束.唯 ...

  7. CocosCreator工程内的命名

    命名结构总体的命名结构遵循以下格式 前缀-内容-尾缀 - 前缀:用来定义node的属性- 内容:node的名字- 尾缀:序列或状态1231. 前缀说明:在开始的时候定义/声明这个节点的属性前缀可以是一 ...

  8. largest rectangle in histogram leetcode

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  9. python爬虫---实现项目(一) Requests爬取HTML信息

    上面的博客把基本的HTML解析库已经说完了,这次我们来给予几个实战的项目. 这次主要用Requests库+正则表达式来解析HTML. 项目一:爬取猫眼电影TOP100信息 代码地址:https://g ...

  10. SMTP error 554 !!

    哇,我真的amazing, incredible!! 我只是想写一个简单的邮件,结果他一直报554错误!!! 期间,通过百度,我发现了可能导致 此,讨厌至极的错误,有N多原因: 但我的原因 谜之离谱! ...