# POJ3255 (secondary short circuit)

Source: Internet
Author: User

Problem Solving Ideas:

According to the Dijkstra thought to do the second short circuit, the first time with the adjacency table, note that the two-way side of the problem and the subscript of the node to 1.

Full code:

`#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include < cmath> #include <set> #include <vector> #include <climits> #include <queue>using namespace Std;typedef Long Long ll;const int maxn = 100001;typedef pair<int, int> p;struct edge{int to, cost;};  int INF = 99999999;int N, r;vector<edge> g[maxn];int dist[maxn];int dist2[maxn];void Solve () {priority_queue<    P, vector<p>, greater<p> > que;    Fill (Dist, dist + n, INF);    Fill (dist2, Dist2 + N, INF);    Dist[0] = 0;    Que.push (P (0, 0));        while (!que.empty ()) {p p = que.top ();        Que.pop ();        int v = p.second, d = p.first;        if (Dist2[v] < D) {continue;            } for (int i = 0; i < g[v].size (); i + +) {Edge &e = G[v][i];            int D2 = d + e.cost; if (Dist[e.to] > D2) {swap (dist[e.to], D2);               Que.push (P (dist[e.to], e.to));                } if (Dist2[e.to] > D2 && dist[e.to] < D2) {dist2[e.to] = D2;            Que.push (P (dist2[e.to], e.to)); }}} cout << dist2[n-1] << Endl;}    int main () {#ifdef Doubleq freopen ("In.txt", "R", stdin);        #endif while (CIN >> n >> r) {int A, B, D;            for (int i = 0; i < R; i + +) {cin >> a >> b >> D;            A--;            B--;            struct Edge temp;            Temp.to = b;            Temp.cost = D;            G[a].push_back (temp);            struct Edge temp2;            Temp2.to = A;            Temp2.cost = D;        G[b].push_back (TEMP2);    } solve (); } return 0;}`

POJ3255 (secondary short circuit)

Related Keywords:

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.