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. Vue-cli构建项目, 组件中js代码引入图片路径问题

    问题描述 .vue的组件分成三个部分, template结构部分, script路径代码, style页面样式 首先, 我们可以在template可以正确引入, 无论是dev, 还是build都没有问 ...

  2. sendRedirect和forward区别

    参考来源:http://www.educity.cn/develop/158970.html 12.6.4  sendRedirect()和forward()方法的区别 HttpServletResp ...

  3. iOS中自定义UITableViewCell的用法

    1.先创建一个View继承 UITableViewCell并使用xib快速建立模型. #import <UIKit/UIKit.h> #import "Score.h" ...

  4. 141 Linked List Cycle 环形链表

    给定一个链表,判断链表中否有环.补充:你是否可以不用额外空间解决此题?详见:https://leetcode.com/problems/linked-list-cycle/description/ J ...

  5. drbd 配置

    DRBD(Distributed Replicated Block Device),DRBD 号称是 "网络 RAID",开源软件,由 LINBIT 公司开发.DRBD实际上是一种 ...

  6. flask搭建

    1.定义路由app.py from flask import Flask, request from flask import Blueprint app = Flask(__name__) test ...

  7. SSAS 系列01- DAX公式常用公式

    计算第一次购买时间 CALCULATE(FIRSTDATE(FactInternetSales[OrderDate]),ALLEXCEPT(FactInternetSales,FactInternet ...

  8. linux截图工具

    推荐:deepin-scrot 满足功能: 能够自定义快捷键(Ctrl+Alt+A) 小巧快速自定义选择区域进行截图 有简单的绘图功能 可以快速的保存到剪切版(双击图片) P.S.:双重截图

  9. Chrome开发者工具关于网络请求的一个隐藏技能

    这个隐藏技能的背景是,最近出于学习目的,我写了一个百度贴吧的网络爬虫,专门爬取一些指定主题的贴吧帖子. 抓取帖子用的JavaScript函数如下: function getPostByAJAX(req ...

  10. (转)使用Spring注解方式管理事务与传播行为详解

    http://blog.csdn.net/yerenyuan_pku/article/details/52885041 使用Spring注解方式管理事务 前面讲解了怎么使用@Transactional ...