TOJ 2944 Mussy Paper

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)

解题:最大权闭合子图

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 110;
 4 const int INF = ~0U>>2;
 5 struct arc {
 6     int to,flow,next;
 7     arc(int x = 0,int y = 0,int z = -1) {
 8         to = x;
 9         flow = y;
10         next = z;
11     }
12 } e[maxn*maxn];
13 int head[maxn],gap[maxn],d[maxn],tot,S,T;
14 void add(int u,int v,int flow) {
15     e[tot] = arc(v,flow,head[u]);
16     head[u] = tot++;
17     e[tot] = arc(u,0,head[v]);
18     head[v] = tot++;
19 }
20 int dfs(int u,int low) {
21     if(u == T) return low;
22     int tmp = 0,minH = T - 1;
23     for(int i = head[u]; ~i; i = e[i].next) {
24         if(e[i].flow) {
25             if(d[u] == d[e[i].to] + 1) {
26                 int a = dfs(e[i].to,min(e[i].flow,low));
27                 e[i].flow -= a;
28                 e[i^1].flow += a;
29                 tmp += a;
30                 low -= a;
31             }
32             if(e[i].flow) minH = min(minH,d[e[i].to]);
33             if(!low) break;
34         }
35     }
36     if(!tmp) {
37         if(--gap[d[u]] == 0) d[S] = T;
38         ++gap[d[u] = minH + 1];
39     }
40     return tmp;
41 }
42 int sap() {
43     memset(gap,0,sizeof gap);
44     memset(d,0,sizeof d);
45     gap[S] = T;
46     int ret = 0;
47     while(d[S] < T) ret += dfs(S,INF);
48     return ret;
49 }
50 int n,m;
51 bool vis[maxn];
52 vector<int>ans;
53 void dfs(int u){
54     vis[u] = true;
55     if(u != S && u != T) ans.push_back(u);
56     for(int i = head[u]; ~i; i = e[i].next)
57         if(!vis[e[i].to] && e[i].flow) dfs(e[i].to);
58 }
59
60 int main() {
61     while(scanf("%d",&n),n) {
62         memset(head,-1,sizeof head);
63         S = n + 1;
64         T = S + 1;
65         int sum = tot = 0,w;
66         for(int u = 1,v; u <= n; ++u) {
67             scanf("%d%d",&w,&m);
68             if(w > 0) {
69                 add(S,u,w);
70                 sum += w;
71             } else add(u,T,-w);
72             while(m--) {
73                 scanf("%d",&v);
74                 add(u,v,INF);
75             }
76         }
77         sum -= sap();
78         if(!sum) puts("Refused");
79         else{
80             ans.clear();
81             memset(vis,false,sizeof vis);
82             dfs(S);
83             printf("%d %d\n",sum,ans.size());
84             sort(ans.rbegin(),ans.rend());
85             for(int i = ans.size()-1; i >= 0; --i)
86                 printf("%d%c",ans[i],i?‘ ‘:‘\n‘);
87         }
88     }
89     return 0;
90 }

时间: 2024-10-12 13:29:51

TOJ 2944 Mussy Paper的相关文章

网络流专栏

最大流 POJ 1273 Drainage Ditches POJ 1274 The Perfect Stall (二分图匹配) POJ 1698 Alice's Chance(构图) POJ 1459 Power Network(构图) POJ 2112 Optimal Milking (二分) POJ 2455 Secret Milking Machine (二分) POJ 3189 Steady Cow Assignment (枚举) POJ 1637 Sightseeing tour (

Soj题目分类

-----------------------------最优化问题------------------------------------- ----------------------常规动态规划  SOJ1162 I-Keyboard  SOJ1685 Chopsticks SOJ1679 Gangsters SOJ2096 Maximum Submatrix  SOJ2111 littleken bg SOJ2142 Cow Exhibition  SOJ2505 The County

网络流柱

最大流量 POJ 1273 Drainage Ditches POJ 1274 The Perfect Stall (二分图匹配) POJ 1698 Alice's Chance(构图) POJ 1459 Power Network(构图) POJ 2112 Optimal Milking (二分) POJ 2455 Secret Milking Machine (二分) POJ 3189 Steady Cow Assignment (枚举) POJ 1637 Sightseeing tour

待刷题目分类

各大OJ题目归类 Posted on 2012 年 8 月 8 日 by admin ---------–最优化问题------------- --------动态规划 SOJ1162 I-Keyboard SOJ2096 Maximum Submatrix SOJ2111 littleken bg SOJ2505 The County Fair SOJ2818 QQ音速 SOJ2469 Exploring Pyramids SOJ1833 Base Numbers SOJ2009 Zeros

网络流题集

最大流POJ 1273 Drainage DitchesPOJ 1274 The Perfect Stall (二分图匹配)POJ 1698 Alice's Chance(构图)POJ 1459 Power Network(构图)POJ 2112 Optimal Milking (二分)POJ 2455 Secret Milking Machine (二分)POJ 3189 Steady Cow Assignment (枚举)POJ 1637 Sightseeing tour (混合图欧拉回路)

Paper Reading: Perceptual Generative Adversarial Networks for Small Object Detection

Perceptual Generative Adversarial Networks for Small Object Detection 2017-07-11  19:47:46   CVPR 2017 This paper use GAN to handle the issue of small object detection which is a very hard problem in general object detection. As shown in the followin

AAAI 2016 paper阅读

本篇文章调研一些感兴趣的AAAI 2016 papers.科研要多读paper!!! Learning to Generate Posters of Scientific Papers,Yuting Qiang, Yanwei Fu, Yanwen Guo, Zhi-Hua Zhou and Leonid Sigal. http://cs.nju.edu.cn/zhouzh/zhouzh.files/publication/aaai16poster.pdf 这篇paper研究从科技论文中生成海报

paper 61:计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接

转载出处:blog.csdn.net/carson2005 以下链接是本人整理的关于计算机视觉(ComputerVision, CV)相关领域的网站链接,其中有CV牛人的主页,CV研究小组的主页,CV领域的paper,代码,CV领域的最新动态,国内的应用情况等等.打算从事这个行业或者刚入门的朋友可以多关注这些网站,多了解一些CV的具体应用.搞研究的朋友也可以从中了解到很多牛人的研究动态.招生情况等.总之,我认为,知识只有分享才能产生更大的价值,真诚希望下面的链接能对朋友们有所帮助.(1)goog

练习题目 3 Game on Paper

 Game on Paper Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game. He took a checkered whi