HDU 1599 Find the Mincost route non-graphic minimum ring

Source: Internet
Author: User

Find the Mincost routeTime limit:1000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2973 Accepted Submission (s): 1197


Problem description Hangzhou has n scenic spots, there are some two-way connection between the scenic spots, now 8600 want to find a tourist route, this route from a point and finally back to a point, assuming the route is V1,v2,.... VK,V1, then must meet the k>2, that is, apart from the starting point to go through at least 2 other different scenic spots, and can not be repeated through the same scenic area. Now 8600 needs you to help him find a route like this, and the less it costs the better.

The first line of input is 2 integers n and m (n <=, M <= 1000), representing the number of scenic spots and the number of roads.
In the next M-line, each row consists of 3 integers a,b,c. Represents a path between A and B and costs C (c <= 100).
Output for each test instance, the minimum value is spent if such a route can be found. If it is not found, output "It's impossible."
Sample Input
3 31 2 12 3 11 3 13 31 2 11 2 32 3 1

Sample Output
3It ' s impossible.

Author8600


Links: http://acm.hdu.edu.cn/showproblem.php?pid=1599


Practice: Before updating the k-1 point as the midpoint, then dp[i][j] and Mp[i][k] and mp[j][k] There must be no duplicate points. Floyd's application problem.


#include <stdio.h> #include <algorithm>using namespace std; #define INF 100000000int mp[110][110];int dp[110][110];int main () {int n,m,a,b,c;while (scanf ("%d%d", &n,&m)! = EOF) {for (int i=1;i<=n;i++) {for (int. j=1;j<=n;j++) {if (i==j) Mp[i][j]=0;elsemp[i][j]=inf;}} for (int i=0;i<m;i + +) {int u,v,c; scanf ("%d%d%d", &u,&v,&c), if (mp[u][v]>c) mp[u][v]=mp[v][u]=c;} for (int i=1;i<=n;i++ {for (int j=1;j<=m;j++) {dp[i][j]=mp[i][j];}} int minn=inf; for (int k=1;k<=n;k++) {for (int. i=1;i<k;i++) {for (int j=1;j<k;j++) {if (i!=j) {int tem=dp[i][j]+mp[i][k]+mp[j][ K]; if (Tem<minn) Minn=tem;  } }} for  (int i=1;i<=n;i++) {for (int j=1;j<=n;j++) {if (i!=j&&i!=k&&j!=k) dp[i][j]=min (dp[i][ J],DP[I][K]+DP[K][J]);  } }  }  





HDU 1599 Find the Mincost route non-graphic minimum ring

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.