Friendship
Time Limit: 2000MS | Memory Limit: 20000K | |
Total Submissions: 10744 | Accepted: 2984 |
Description
In modern society, each person has his own friends. Since all the people are very busy, they communicate with each other only by phone. You can assume that people A can keep in touch with people B, only if 1. A knows B's phone number, or 2. A knows people C's phone number and C can keep in touch with B. It's assured that if people A knows people B's number, B will also know A's number. Sometimes, someone may meet something bad which makes him lose touch with all the others. For example, he may lose his phone number book and change his phone number at the same time. In this problem, you will know the relations between every two among N people. To make it easy, we number these N people by 1,2,...,N. Given two special people with the number S and T, when some people meet bad things, S may lose touch with T. Your job is to compute the minimal number of people that can make this situation happen. It is supposed that bad thing will never happen on S or T.
Input
The first line of the input contains three integers N (2<=N<=200), S and T ( 1 <= S, T <= N , and S is not equal to T).Each of the following N lines contains N integers. If i knows j's number, then the j-th number in the (i+1)-th line will be 1, otherwise the number will be 0. You can assume that the number of 1s will not exceed 5000 in the input.
Output
If there is no way to make A lose touch with B, print "NO ANSWER!" in a single line. Otherwise, the first line contains a single number t, which is the minimal number you have got, and if t is not zero, the second line is needed, which contains t integers in ascending order that indicate the number of people who meet bad things. The integers are separated by a single space. If there is more than one solution, we give every solution a score, and output the solution with the minimal score. We can compute the score of a solution in the following way: assume a solution is A1, A2, ..., At (1 <= A1 < A2 <...< At <=N ), the score will be (A1-1)*N^t+(A2-1)*N^(t-1)+...+(At-1)*N. The input will assure that there won't be two solutions with the minimal score.
Sample Input
3 1 31 1 01 1 10 1 1
Sample Output
12
题目链接:
给了一个用邻接矩阵表示的无向图,断开S与T点的最少点数集且这个集合不能包含S与T,若这个集合不为0,则输出字典序最小的一种方案。
题意显然是求最少割点集,肯定要拆点了, 考虑原图一个人的影响,去掉这个人则与与他直接连接的人均无法连接到他,因此自身拆出来的边流量为1,为了保证S与T不在集合中,这两个点的边流量为INF,然后顺序枚举各个点,若去掉当前点流量变小了当前边权的值,则说明这个点就在割边集中。
代码:
#include#include #include #include #include #include #include #include #include #include #include #include #include #include #include