Iot language (Short Circuit)

Source: Internet
Author: User

 

After reading the questions, I thought that this was the best bare shortest path. I wrote dijstra and gave priority to queue optimization (This question will be stuck in spfa and spfa died on the spot ).

Score Jun's death

Warn yourself that the array range must be clear before writing, N and M should not be mixed, and the condition of "inf" must be clearly written, the scope cannot be defined so clearly (the result is wrong ).

Check the array range several times when checking for errors.

There is no need to explain the bare shortest path. Set the weight of the MTH edge to 0. Run the Shortest Path First to shield the M-th edge from running the long path, finally, you can determine who to output the weight of the last edge.

1 # include <iostream> 2 # include <cstdio> 3 # include <cstdlib> 4 # include <cstring> 5 # include <queue> 6 # include <algorithm> 7 8 # define for (I, a, B) for (register int I = A; I <= B; ++ I) 9 # define re Register10 # define LLG long long11 # define INF 0x7f7f7f12 # define PN putchar ('\ n') 13 using namespace STD; 14 const int n = 2e5 + 10, M = 5e5 + 10; 15 int head [N], NXT [M * 2], V [M * 2], CNT = 0; 16 int n, m, K, x, Y; 17 llg w [M * 2], DIS, CDIs, Z; // The m in this place is written as N, and half of the score is scored. 18 inline void read (Int & V) {19 V = 0; 20 char c = getchar (); 21 While (C <'0' | C> '9 ') C = getchar (); 22 while (C> = '0' & C <= '9') V = V * 10 + C-'0 ', C = getchar (); 23} 24 inline void read (LLG & V) {25 V = 0; 26 char c = getchar (); 27 while (C <'0' | C> '9') C = getchar (); 28 while (C> = '0' & C <= '9 ') V = V * 10 + C-'0', c = getchar (); 29} 30 void write (llg x) {31 if (x> 9) write (X/10); 32 int xx = x % 10; 33 putchar (xx + '0'); 34} 35 void add (int ux, int VX, LLG wx) {36 CNT ++; 37 NXT [CNT] = head [UX]; head [UX] = CNT; V [CNT] = VX; W [CNT] = wx; 38 CNT ++; 39 NXT [CNT] = head [VX]; head [VX] = CNT; V [CNT] = UX; W [CNT] = wx; 40} 41 42 struct QR {43 llg x; 44 int ID; 45 bool operator <(const QR & A) const {46 Return. x <X; 47} 48 }; 49 priority_queue <QR> q; 50 51 LLG d [N], NF; 52 void DJs (int chs) {53 memset (D, INF, sizeof (d); 54 NF = d [0]; 55 d [1] = 0; q. push (QR) {0, 1}); 56 while (! Q. empty () {57 qr tp = Q. top (); q. pop (); 58 If (d [TP. id] <TP. x) continue; 59 for (Re int I = head [TP. id]; I; I = NXT [I]) {60 if (CHS & W [I] = 0) continue; 61 int VV = V [I]; 62 if (TP. X + W [I] <D [VV]) {63 d [VV] = TP. X + W [I]; 64 Q. push (QR) {d [VV], VV}); 65} 66} 67} 68} 69 70 int main () {71 // freopen ("monogatari. in "," r ", stdin); 72 // freopen (" monogatari. out "," W ", stdout); 73 read (n); read (m); read (k); 74 for (I, 1 M-1) {75 read (x); read (y); Re AD (z); 76 add (x, y, z); 77} 78 read (x); read (y); add (X, Y, 0 ); 79 DJs (0); Dis = d [N]; 80 DJs (1); CDIS = d [N]; 81 82 for (I, 1, K) {83 read (x); 84 If (DIS> = NF) {// Where> = forgot to write = .. 85 printf ("+ INF \ n"); 86 continue; 87} 88 If (DIS + x <CDIs) {89 write (DIS + x); PN; 90} else {91 write (CDIS); PN; 92} 93} 94 fclose (stdin); fclose (stdout); 95 return 0; 96}

 

Iot language (Short Circuit)

Related Article

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.