"CF" 142 Div.1 B. Planes

Source: Internet
Author: User

SPFA. Note The state transition condition, ANS solution needs to be solved in the BFS center. As long as the location n is reached, there is no need to wait for other tourist.
It's pretty simple, pay attention to the details.

1 /*229B*/2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <stack>8#include <vector>9#include <deque>Ten#include <algorithm> One#include <cstdio> A#include <cmath> -#include <ctime> -#include <cstring> the#include <climits> -#include <cctype> -#include <cassert> -#include <functional> +#include <iterator> -#include <iomanip> + using namespacestd; A //#pragma COMMENT (linker, "/stack:102400000,1024000") at  - #defineSTI set<int> - #defineStpii Set<pair<int, int> > - #defineMpii map<int,int> - #defineVI vector<int> - #definePII pair<int,int> in #defineVpii vector<pair<int,int> > - #defineRep (I, A, n) for (int i=a;i<n;++i) to #definePer (i, a, n) for (int i=n-1;i>=a;--i) + #defineCLR Clear - #definePB Push_back the #defineMP Make_pair * #defineFIR First $ #defineSEC SecondPanax Notoginseng #defineAll (x) (x). Begin (), (x). End () - #defineSZ (x) ((int) (x). Size ()) the #defineLson L, Mid, rt<<1 + #defineRson mid+1, R, rt<<1|1 A  the Const intMAXN = 1e5+5; + Const intINF =0x3f3f3f3f; - Vpii E[MAXN]; $ Vpii T[MAXN]; $ intDIS[MAXN]; - BOOLVISIT[MAXN]; - intA[MAXN], B[MAXN]; the  - intMain () {WuyiIos::sync_with_stdio (false); the #ifndef Online_judge -Freopen ("data.in","R", stdin); WuFreopen ("Data.out","W", stdout); -     #endif About  $     intN, M; -     intu, V, W; -  -scanf"%d%d", &n, &m); A      while(m--) { +scanf" %d%d%d", &u, &v, &W); the E[U].PB (MP (V, W)); - E[V].PB (MP (U, W)); $     } theRep (I,1, n+1) { thescanf"%d", &m); theRep (J,1, m+1) thescanf"%d", &a[j]); -B[M] =1; inPer (J,1, M) { the             if(a[j]+1= = a[j+1]) theB[J] = b[j+1] +1; About             Else theB[J] =1; the         } theRep (J,1, m+1) + T[I].PB (MP (A[j], b[j])); -     } the Bayi     inti, TMP; the     intAns =INF; thePII P (0,0); - Vpii::iterator iter; -queue<int>Q; theQ.push (1); thememset (DIS,0x3f,sizeof(DIS)); the     //May is has 0 in t[1] theITER = Upper_bound (All (t[1]), p); -     if(iter!=t[1].end () && iter->fir==0) { thedis[1] = iter->sec; the}Else { thedis[1] =0;94     } thevisit[1] =true; the  the      while(!Q.empty ()) {98U =Q.front (); About Q.pop (); -Visit[u] =false;101          for(i=0; I<sz (E[u]); ++i) {102v =E[u][i].fir;103W =e[u][i].sec;104TMP = Dis[u] +W; the             if(V==n && tmp<ans)106Ans =tmp;107P.fir =tmp;108ITER =Upper_bound (All (T[v]), p);109             if(Iter!=t[v].end () && iter->fir==tmp) { theTMP + = iter->sec;111             } the             if(TMP <Dis[v]) {113DIS[V] =tmp; the                 if(!Visit[v]) { theVISIT[V] =true; the Q.push (v);117                 }118             }119         } -     }121 122Ans = ans==inf? -1: ans;123printf"%d\n", ans);124  the #ifndef Online_judge126printf"Time =%d.\n", (int) clock ());127     #endif - 129     return 0; the}

"CF" 142 Div.1 B. Planes

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.