[2016-04-02] [POJ] [2387] [Til the Cows Come Home]

Source: Internet
Author: User

    • Time: 2016-04-02-10:34:36 Saturday
    • Title Number: [2016-04-02][poj][2387][til the Cows Come Home]
    • Topic: given n nodes and T-path, the shortest-circuit length of N to 1 is obtained.
    • Analysis: Run the shortest possible time
    • Problems encountered:
      • is said to be multiple sides, if the adjacency matrix is used to update the minimum value,
      • This problem is first input t, and then enter N, input the time to read wrong, infinite wa ...
  
 
  1. #include <queue>
  2. #include <cstring>
  3. #include <cstdio>
  4. using namespace std;
  5. const int maxn = 1000 + 10;
  6. const int maxe = 2000 + 10;
  7. struct mNode{
  8. int u,c;
  9. Mnode ( int _u = 0 int _c = 0 ): u ( _u c ( _c
  10. bool operator < (const mNode & a)const{
  11. return c > a.c;
  12. }
  13. };
  14. struct Edge{
  15. int v,c;
  16. Edge(int _v = 0,int _c = 0):v(_v),c(_c){}
  17. };
  18. vector<Edge> e[maxe];
  19. bool vis[maxn];
  20. int d[maxn];
  21. void Dijkstra(int s){
  22. memset(vis,0,sizeof(vis));
  23. memset(d,0x3f,sizeof(d));
  24. priority_queue<mNode> q;
  25. d[s] = 0;
  26. q.push(mNode(s,0));
  27. mNode tmp;
  28. while(!q.empty()){
  29. tmp = q.top();
  30. q.pop();
  31. int u = tmp.u;
  32. if(vis[u]) continue;
  33. vis[u] = 1;
  34. for(int i = 0;i < e[u].size();++i){
  35. Edge & me = e[u][i];
  36. if (! vis [ me v && D [ me v > D Span class= "pun" >[ u ] + me c
  37. D [me v = D [ u ] + me c
  38. q.push(mNode(me.v,d[me.v]));
  39. }
  40. }
  41. }
  42. }
  43. inline void addedge(int u,int v,int c){
  44. e[u].push_back(Edge(v,c));
  45. }
  46. int main(){
  47. int n,t,a,b,c;
  48. scanf("%d%d",&t,&n);
  49. for(int i = 0;i < t; ++i){
  50. scanf("%d%d%d",&a,&b,&c);
  51. addedge(a,b,c);
  52. addedge(b,a,c);
  53. }
  54. Dijkstra(n);
  55. printf("%d\n",d[1]);
  56. return 0;
  57. }


From for notes (Wiz)

[2016-04-02] [POJ] [2387] [Til the Cows Come Home]

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.