UVa 140 Bandwidth: Enumerating all permutations & pruning searches

Source: Internet
Author: User
Tags time limit

140-bandwidth

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_ problem&problem=76

Given a graph (v,e) where V is a set of nodes and E are a set of arcs in VXV, and anordering on the elements in V, then the Bandwidth of a nodev is defined as the maximum distance into the ordering betweenv and any node to which it are connected in The graph. The bandwidth of the ordering is then defined as the maximum of the individual. For example, consider the following graph:

This can is ordered in many ways, two of which are illustrated below:

For this orderings, the bandwidths of the nodes (in order) are 6, 6, 1, 4, 1, 1, 6, 6 giving a ordering bandwidth of 6, and 5, 3, 1, 4, 3, 5, 1, 4 giving an ordering bandwidth of 5.

Write a program that'll find the ordering of a graph that minimises the bandwidth.

Input

Input would consist of a series of graphs. Each graph would appear on a line by itself. The entire file is terminated by a line consisting of a single#. For each graph, the input would consist of a series of records separated by '; Each record would consist of a node name (a single upper case character in the "a ' to ' Z"), followed by a ': ' and At least one of its neighbours. The graph would contain no more than 8 nodes.

Output

Output would consist of one line for each graph, listing the ordering of the nodes followed by a arrow (->) and the ban Dwidth for that ordering. All items must is separated from their neighbours by exactly one space. If more than one ordering produces the same bandwidth, then choose the smallest in lexicographic ordering, which is the one That would appear the alphabetic listing.

Sample input

A:FB; B:GC;D:GC; F:agh; E:HD
#

Sample output

A B C F G D H E-> 3

The enumeration is all arranged and cut off when encountering Nowmin > _min.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.