1999 Central European Olympiad on Informatics-sightseeing trip

Source: Internet
Author: User

Algorithm Hints

Minimum ring problem

Main Topic

On a weighted graph, find at least 3 points with a weighted value and a minimum ring, and press the point on the ring on the sequential output ring. There are heavy edges, no self-loops.

Approach Analysis

Refer to the minimum loop problem, when updating dist[i][j], record the update of its point k to facilitate backtracking paths.

Reference Code
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <queue>5#include <algorithm>6 7 using namespacestd;8 9 #defineMAXN 110Ten #defineINF 0x3f3f3f3f One #defineMAX (A, B) (A&GT;B?A:B) A #defineMIN (A, B) (A&LT;B?A:B) - #defineABS (M) (m<0?-m:m) -typedefLong LongLL; the  - intN,m,ans; - intUPDATE[MAXN][MAXN],ROAD[MAXN]; - intDIS[MAXN][MAXN],E[MAXN][MAXN]; +  - voidInit () + { AMemset (E,0x3f,sizeof(e)); at     inti,u,v,d; -      for(i=1; i<=m;++i) { -scanf"%d%d%d",&u,&v,&d); -e[u][v]=min (e[u][v],d); -e[v][u]=E[u][v]; -     } in } -  to voidGetroad (intIintj) + { -     if(! UPDATE[I][J]) road[++road[0]]=i; the     Elsegetroad (I,update[i][j]), Getroad (update[i][j],j); * } $ Panax Notoginseng voidFloyd () - { the     intI,j,k; ans=INF; +memcpy (Dis,e,sizeof(e)); Amemset (Update,0,sizeof(Update)); the      for(k=1; k<=n;++k) { +          for(i=1; i<k;++i) -              for(j=i+1; j<k;++j) $                 if(0ll+dis[i][j]+e[i][k]+e[k][j]<ans) { $ans=dis[i][j]+e[i][k]+E[k][j]; -road[0]=0; Getroad (i,j); -road[++road[0]]=J; theroad[++road[0]]=K; -                 }Wuyi          for(i=1; i<=n;++i) the              for(j=1; j<=n;++j) -                 if(dis[i][k]+dis[k][j]<Dis[i][j]) { Wudis[i][j]=dis[i][k]+Dis[k][j]; -update[i][j]=K; About                 } $     } -     if(Ans==inf) printf ("No solution.\n"); -     Else{ -          for(i=1; i<road[0];++i) printf ("%d", Road[i]); Aprintf"%d\n", Road[i]); +     } the } -  $ intMain () the { the      while(SCANF ("%d", &n), n!=-1){ thescanf"%d",&m); the Init (); - Floyd (); in     } the     return 0; the}
View Code

Topic links

1999 Central European Olympiad on Informatics-sightseeing trip

1999 Central European Olympiad on Informatics-sightseeing trip

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.