QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100

#18557. 图稳定化

統計

考虑一个含有 $n$ 个顶点的无向图,其中第 $i$ 个顶点上写有整数 $a_i$。如果存在一条边连接两个顶点,则称它们为邻居。

如果顶点 $i$ 存在一个邻居 $j$,满足以下条件中的至少一个,则称顶点 $i$ 是稳定的

  • $a_j < a_i$;
  • $a_j \oplus a_i = k$,其中 $\oplus$ 表示按位异或(XOR)运算符。

如果顶点 $i$ 不存在任何这样的邻居,则称 $i$ 是不稳定的

图的稳定化过程定义如下:

  1. 如果图中没有不稳定的顶点,则结束该过程。否则,转到步骤 2。
  2. 设 $v$ 是索引(编号)最小的不稳定顶点。从图中删除 $v$ 以及所有与 $v$ 相连的边,然后转到步骤 1。

定义图的稳定性为图稳定化后剩余的顶点数量。

给你一个数组 $a$、一个整数 $k$ 和一个无向图,其中每条边都有一个与之关联的权值(代价)。你可以从图中删除任意数量的边(可以不删,也可以全删)。你的目标是通过删除边,使得:

  • 最终得到的图的稳定性最大;
  • 在保证稳定性最大的前提下,被删除边的总权值最大。

输入格式

第一行包含三个整数 $n, m, k$ ($1 \le n \le 100$;$0 \le m \le \frac{n(n-1)}{2}$;$1 \le k \le 127$)。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 127$)。

接下来 $m$ 行,其中第 $i$ 行包含三个整数 $x_i, y_i, c_i$ ($1 \le x_i, y_i \le n$;$x_i \ne y_i$;$1 \le c_i \le 10^9$) —— 表示第 $i$ 条边的两个端点和它的权值。

输入附加限制:任意两个顶点之间最多只有一条边相连。

输出格式

首先,输出一个整数 $e$ ($0 \le e \le m$) —— 你删除的边数。

然后,以任意顺序输出 $e$ 个互不相同的介于 $1$ 到 $m$ 之间的整数 —— 这些边的索引(按输入顺序从 $1$ 到 $m$ 编号)。如果有多个最优解,你可以输出其中任意一个。

样例

输入样例 1

5 6 1
0 1 2 2 2
1 2 1
1 3 2
2 3 3
3 4 4
3 5 5
4 5 6

输出样例 1

4
3 4 5 6

输入样例 2

8 10 3
34 5 6 33 4 7 1 4
1 3 11
4 1 15
8 6 10
5 7 1
5 6 10
5 2 5
2 6 2
3 2 4
5 3 1
4 2 2

输出样例 2

5
2 4 6 7 9

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.