"Shortest circuit" lightoj 1099-not the best second short circuit

Source: Internet
Author: User

Click to open link

Test instructions: The second short circuit, the title definition: must be greater than the shortest circuit and the road can be repeated walk;

Open two-dimensional array d[n][2] record the shortest and second short circuits, respectively

#include <cstdio> #include <cstring> #include <cstdlib> #include <string> #include <iostream > #include <algorithm> #include <sstream> #include <cmath>using namespace std; #include <queue > #include <stack> #include <set> #include <vector> #include <deque> #include <map># Define Cler (arr, Val) memset (arr, Val, sizeof (arr)) #pragma comment (linker, "/stack:102400000,102400000") typedef long LO ng Ll;const int maxn = 5010+1;const int MAXM = 240000;const int INF = 0x3f3f3f3f;const int mod = 1000000007;int d[maxn][2 ],head[maxn],tol;bool vis[maxn][2];struct node{int u,v,val,next;}    Edge[maxm];void addedge (int u,int v,int W) {edge[tol].u=u,edge[tol].v=v,edge[tol].val=w,edge[tol].next=head[u];    head[u]=tol++;    EDGE[TOL].U=V,EDGE[TOL].V=U,EDGE[TOL].VAL=W,EDGE[TOL].NEXT=HEAD[V]; head[v]=tol++;}    void Dij (int n) {for (int i=0;i<=n;i++) D[i][0]=d[i][1]=inf,vis[i][0]=vis[i][1]=false;    d[0][0]=0; while (trUE) {int v=-1,k;        int minlen=inf; for (int u=0;u<n;u++) {for (int l=0;l<2;l++) if (!vis[u][l]&& (v==-1| |                    D[u][l]<minlen)) {minlen=d[u][l];                    K=l;                V=u;        }} if (V==-1) break;        Vis[v][k]=true;            for (int i=head[v];~i;i=edge[i].next) {int u=edge[i].v;//target int cost=d[v][k]+edge[i].val;                if (Cost<d[u][0]) {d[u][1]=d[u][0];            D[u][0]=cost;            } else if (Cost<d[u][1]&&cost>d[u][0]) {d[u][1]=cost;   }}}}int Main () {#ifndef Online_judge freopen ("In.txt", "R", stdin);    Freopen ("OUT.txt", "w", stdout); #endif int T,n,m,u,v,w,cas=1;    cin>>t;        while (t--) {Cler (head,-1);        tol=0;        cin>>n>>m;    int a=0;    for (int i=0;i<m;i++) {scanf ("%d%d%d", &u,&v,&w);            A=max (A,u);            A=max (A,V);            U--, v--;        Addedge (U,V,W);        } dij (a);    printf ("Case%d:%d\n", cas++,d[n-1][1]); } return 0;}


"Shortest circuit" lightoj 1099-not the best second short circuit

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.