SalesforceOA #20
Get Node To Remove
估计中等可在线判题
考点(AI 标注)并查集
Delete exactly one node together with its incident edges, then let the infection spread along undirected edges from the remaining initially infected nodes until no new node is infected. A healthy node may be deleted. Find the deletion that minimizes the final number of infected nodes, breaking ties by the smallest 1-based number.
输入格式
The first line contains n m, the second line contains n initial infection flags, each 0/1, and then m lines follow with 1-based edges u v. 1≤n≤1000, 0≤m≤min(n(n−1)/2,1000); this site treats the graph as a simple undirected graph, with no duplicate edges and no self-loops.
输出格式
Output the number of the node to delete. Even if there is no infection, one node must still be deleted.
样例 1
输入:
9 5
0 0 1 0 1 0 0 0 0
1 2
2 3
4 5
6 7
7 8
输出:
3
样例 2
输入:
5 4
1 1 1 1 1
1 2
2 3
3 4
4 5
输出:
1
样例 3
输入:
6 5
1 1 0 0 0 0
1 3
2 3
3 4
4 5
5 6
输出:
3
样例说明
The answers are 3, 1, and 3. In the third example, healthy node 3 is a cut vertex, and deleting it is better than deleting any single infection source. Original example 1 omitted node 1 from its spread set; the deletion answer 3 is unchanged.