QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 32 MB 總分: 10 公開測試

#11653. 旅行社

统计

Byteland 的居民最近比以往任何时候都更频繁地旅行。富有进取心的 ByteMan 萌生了开设一家旅行社的想法。第一天有 $n$ 位顾客来到旅行社(我们将他们编号为 $1$ 到 $n$),每位顾客都想去旅行。不幸的是,每位顾客都有自己的要求。

你的任务是帮助 ByteMan 选择应该参加旅行的顾客,以使 ByteMan 的利润最大化。

每位顾客都告诉了 ByteMan 这次旅行对他们个人的价值。设 $x_{i}$ 为第 $i$ 位顾客的旅行价值($-1\,000\,000 \le x_{i} \le 1\,000\,000$)。如果 $x_{i} \ge 0$,则该顾客为旅行支付 $x_{i}$ debillar;如果 $x_{i} < 0$,则如果该顾客参加旅行,ByteMan 必须支付给第 $i$ 位顾客 $-x_{i}$ debillar。

除了财务要求外,顾客还有社交要求。第 $i$ 位顾客有 $k_{i}$ ($0 \le k_{i} \le n - 1$) 项此类要求;第 $i$ 位顾客的第 $j$ 项要求由一对整数 $(a_{ij}, b_{ij})$ 表示($1 \le a_{ij} \le n$,$a_{ij} \ne i$,$1 \le b_{ij} \le 1\,000\,000$)。该要求意味着:如果第 $i$ 位顾客参加旅行,那么第 $a_{ij}$ 位顾客也必须参加旅行,否则第 $i$ 位顾客的旅行成本必须降低 $b_{ij}$ debillar(可能会出现某些顾客的旅行成本从正数降为负数,ByteMan 将不得不向这些顾客支付一些 debillar,从而使他们在未满足部分社交要求的情况下参加旅行)。

帮助 ByteMan 选择应该参加旅行的顾客,以使 ByteMan 的利润最大化(参加旅行的顾客人数没有限制)。

任务

共有 11 个测试用例,可以从此处下载。每个测试用例都在一个单独的文件 biu$k$.in 中,其中 $k$ 是用例编号($0 \le k \le 10$)。该任务的解决方案应为一个程序,从标准输入读取一个整数 $k$,并将第 $k$ 个测试用例的解输出到标准输出。biu0.in 的解不计入评分。

输出文件的第一行应包含一个整数 $k$ ($0 \le k \le n$),即 ByteMan 应带去旅行的顾客人数。如果 $k$ 为正数,则第二行应包含 $k$ 个整数,用空格分隔,表示应参加旅行的顾客编号。如果存在多个最优解,输出其中任意一个即可。顾客编号可以以任何顺序给出。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 1\,000$),表示旅行社的顾客人数。接下来的 $n$ 行描述顾客信息。第 $i+1$ 行($1 \le i \le n$)包含整数 $x_{i}$ ($-1\,000\,000 \le x_{i} \le 1\,000\,000$) 和 $k_{i}$ ($0 \le k_{i} \le n - 1$),随后是 $k_{i}$ 对整数 $(a_{ij}, b_{ij})$ ($1 \le a_{ij} \le n$,$a_{ij} \ne i$,$1 \le b_{ij} \le 1\,000\,000$) —— 行内所有数字均由空格分隔。你可以假设每位顾客对于其他任何特定顾客最多只有一项社交要求。

样例

输入 1

4
5 0
6 2 1 10 3 1
-10 0
1 2 1 10 2 10

输出 1

3
1 2 4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.