0203. Unique attack

Input file name: attack.in
Output file name: attack.out
Time limit: 2 s
Memory limit: 64 megabytes

N supercomputers in the United States of Antarctica are connected into a network. A network has a simple topology: M different pairs of supercomputers are connected to each other by an optical fibre. All connections are two-way, that is, they can be used in both directions. Data can be transmitted from one computer to another either directly by a fibre, or using some intermediate computers.

A group of terrorists is planning to attack the network. Their goal is to separate two main computers of the network, so that there is no way to transmit data from one of them to another. For each fibre the terrorists have calculated the sum of money they need to destroy the fibre. Of course, they want to minimize the cost of the operation, so it is required that the total sum spent for destroying the fibres was minimal possible.

Now the leaders of the group wonder whether there is only one way to do the selected operation. That is, they want to know if there are no two different sets of fibre connections that can be destroyed, such that the main supercomputers cannot connect to each other after it and the cost of the operation is minimal possible.

Input file

The first line of the input file contains N, M, A and B (2 ≤ N ≤ 800, 1 ≤ M ≤ 10000, 1 ≤ A, B ≤ N, A ≠ B), specifying the number of supercomputers in the network, the number of fibre connections, and the numbers of the main supercomputers respectively.

Next M lines describe fibre connections. For each connection the numbers of the computers it connects are given and the cost of destroying this connection. It is guaranteed that all costs are non-negative integer numbers not exceeding 105, no two computers are directly connected by more than one fibre, no fibre connects a computer to itself and initially there is the way to transmit data from one main supercomputer to another.

Output file

If there is only one way to perform the operation, output "UNIQUE". In the other case output "AMBIGUOUS".

Examples:

attack.inattack.out
4 4 1 2 1 2 1 2 4 2 1 3 2 3 4 1 UNIQUE
4 4 1 2 1 2 1 2 4 1 1 3 2 3 4 1 AMBIGUOUS


Source: Petrozavodsk Winter 2004. Andrew Stankevich Contest 4, Friday, January 30
Author: Andrew Stankevich

Discuss       Submit a solution



Printable version