JZOJ5650. NOI2018 Simulator 4.13 Bus Tour

Source: Internet
Author: User
Topics


Main Topic

is to give an n-point graph,
The Benquan of each edge is changed over time.
The shortest path to all points, starting from 1. Solving

For each edge,
The time to reach the next point through it is to add it to the waiting time.
Is the SPFA above the Benquan position slightly modified on it. Code

#include <queue> #include <cstdio> #include <iostream> #include <algorithm> #include < cstring> #include <string.h> #include <cmath> #include <math.h> #include <time.h> #define LL l Ong long #define N 200003 #define M 103 #define DB double #define P putchar #define G getchar #define INF 998244353 #defin
e Pi 3.1415926535897932384626433832795 using namespace std;
Char ch;
    void read (int &n) {n=0;
    Ch=g ();
    while ((ch< ' 0 ' | | ch> ' 9 ') && ch!= '-') ch=g ();
    ll W=1;
    if (ch== '-') w=-1,ch=g ();
    while (' 0 ' <=ch && ch<= ' 9 ') n= (n<<3) + (n<<1) +ch-' 0 ', ch=g ();
N*=w; } int max (int a,int b) {return a>b?a:b;} int min (int a,int b) {return a<b?a:b;} ll ABS (LL x) {return x<0?-x:x;} ll SQR (ll x) {return x*x;} void Write (ll x) {if (x>9) write (X/10);

P (x%10+ ' 0 ');}
int Nxt[n*2],to[n*2],k[n*2],b[n*2],lst[n],tot;
int n,m,s,t[n];
int q[n*10],f[n],l,r,x,y,st,v,w;

BOOL Bz[n]; void ins (int x,int y,inT T1,int T2) {nxt[++tot]=lst[x];
    To[tot]=y;
    Lst[x]=tot;
    K[TOT]=T1;
B[tot]=t2;
    } int main () {freopen ("bus.in", "R", stdin);

    Freopen ("Bus.out", "w", stdout);
    Read (n); read (m);
        for (int i=1;i<=m;i++) {read (s); Read (t[1]);
        for (int j=2;j<=s;j++) read (T[j]), INS (t[j-1],t[j],s,j-2);
    Ins (t[s],t[1],s,s-1);
    } memset (F,127,sizeof (f));

    memset (bz,1,sizeof (BZ));
    for (f[q[r=1]=1]=l=bz[1]=0;l<r;)
        {St=f[x=q[++l]];
            for (int i=lst[x];i;i=nxt[i]) {y=to[i];w=st/k[i];
            if (St%k[i]>b[i]) w++;
            v=w*k[i]+b[i]+1;
                if (f[y]>v) {f[y]=v;
            if (Bz[y]) bz[q[++r]=y]=0;
    }} bz[x]=1;
            } for (int i=2;i<=n;i++) if (f[i]<f[0]) write (F[i]), P (");

    else P ('-'), p (' 1 '), P (');
return 0;
 }

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.