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. 线段树+离散化 POJ 2528 Mayor's posters

    题目传送门 题意:在一面墙上贴海报,有先后顺序,问最后有多少张不同的海报(指的是没被覆盖或者只是部分覆盖的海报) 分析:这题数据范围很大,直接搞超时+超内存,需要离散化:离散化简单的来说就是只取我们需 ...

  2. Python: How to iterate list in reverse order

    #1 for index, val in enumerate(reversed(list)): print len(list) - index - 1, val #2 def reverse_enum ...

  3. nginx中常见的变量

    $arg_PARAMETER        客户端GET请求PARAMETER的值. $args     请求中的参数. $binary_remote_addr 二进制码形式的客户端地址. $body ...

  4. AJPFX关于集合的几种变量方式

    package com.java.test; import java.util.ArrayList;import java.util.Enumeration;import java.util.Iter ...

  5. es6语法错误

    哇,今天折腾了好久解决了一个问题,记录一下. 错误: 解决方法:配置babel,将es6语法转换成es5语法 1. 全局安装babel: npm install babel-cli -g 2. 本地安 ...

  6. pandas DataFrame 警告(SettingWithCopyWarning)

    转自:https://www.cnblogs.com/pig-fly/p/7875472.html 刚接触python不久,编程也是三脚猫,所以对常用的这几个工具还没有一个好的使用习惯,毕竟程序语言是 ...

  7. Python3 写入文件

    Demo: file = open("test.txt", "wb")file.write("string") 上面这段代码运行会报类型错误 ...

  8. Xilinx HLS

    Xilinx 的高层次综合(High Level Synthesis, HLS)技术是将C/C++/SystemC软件语言转换成Verilog或VHDL硬件描述语言的技术.现已应用在SDAccel,S ...

  9. 搜索模板elasticsearch

    搜索: like 对中文分词效率与支持都不太友好elasticsearch 实时的(效率高).分布式(可扩展)的搜索和分析引擎,基于Lucene全文搜索引擎工具包,算法基于倒排索引算法(eg:一篇文章 ...

  10. css3纯手写loading效果

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...