1922: [Sdoi2010] Mainland hegemony |dijkstra

Source: Internet
Author: User

The shortest-circuit dafa is good. Orz Huang Seniors

Set d 1[x],d 2[x] Arrival time for City X, time to enter
max(d 1[x],d 2[x]) For the real time of entry
d[x] Record city x protected by how many cities
Take out a city with the smallest real entry time in each heap
Update the city that it leads to d 1 , protect the city's d 2
Protect the city's d – 1
If d=0 , you can enter the heap
Complexity of (N+m)Lo g 2 N

Huang write more clearly, it seems that many people have used the matrix of the appearance of the map, no wonder the card into the first page

#include <iostream>#include <algorithm>#include <cstdlib>#include <cstdio>#include <cstring>#include <vector>#include <cmath>#include <complex>#include <queue>#include <map>#include <set>#define INF 11111111111111LL#define LL Long Long#define PA pair<ll,int>#define N 80005using namespace STD;intSC () {intI=0;CharC=getchar (); while(c>' 9 '|| c<' 0 ') C=getchar (); while(c>=' 0 '&& c<=' 9 ') i=i*Ten+c-' 0 ', C=getchar ();returni;} ll D1[n],d2[n],d[n];intHead[n],nxt[n],lst[n],vis[n];intHead[n],nxt[n],lst[n],v[n];intN,M,TOT,TOT;PRIORITY_QUEUE&LT;PA, vector<pa>,greater<pa> >q;voidInsertintXintYintz) {lst[++tot]=y;nxt[tot]=head[x];head[x]=tot;v[tot]=z;}voidInsertintXintY) {d[y]++; Lst[++tot]=y; NXT[TOT]=HEAD[X]; Head[x]=tot;}voidDijkstra () { for(intI=1; i<=n;i++) D1[i]=inf; Q.push (Make_pair (d1[1]=d2[1]=0,1)); while(!q.empty ()) {intX=q.top (). Second;q.pop ();if(Vis[x])Continue; vis[x]=1; ll Now=max (D1[x],d2[x]); for(intI=head[x];i;i=nxt[i])if(Now+v[i]<d1[lst[i]]) {D1[lst[i]]=now+v[i];if(d[lst[i]]==0) Q.push (Make_pair (Max (D1[lst[i]],d2[lst[i]), lst[i])); } for(intI=head[x];i;i=nxt[i]) {D2[lst[i]]=max (D2[lst[i]],now);if(! (--d[lst[i]))        Q.push (Make_pair (Max (D1[lst[i]],d2[lst[i]), lst[i])); }    }}intMain () {N=SC (); M=sc (); for(intI=1; i<=m;i++) {intX=SC (), Y=SC (), Z=SC ();    Insert (x, y, z); } for(intI=1; i<=n;i++) {intS=SC (); for(intj=1; j<=s;j++) {intX=SC ();        Insert (x,i); }} Dijkstra ();printf("%lld\n", Max (D1[n],d2[n]));}

1922: [Sdoi2010] Mainland hegemony |dijkstra

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.