Bzoj 5047 Space Transfer Device shortest circuit

Source: Internet
Author: User
Tags current time

There are n planets in Description space that can be transferred between them through a space transfer device. The space transfer device is divided into m species, and the first I device can be described by 4 parameter a_i,b_i,c_i,d_i. Because of the problem of space-time jitter, it is forbidden to use space transfer devices at non-integer moments. If you use the appliance at integer s, it Takes (a_i*s+b_i) mod c_i to +d_i unit time to complete the transfer. Now is the s moment, small q on Planet 1th, please write a program to calculate the minimum time required from planet 1th to each planet. The first line of Input contains 4 positive integers n,m,s,e (2<=n<=100000,1<=m<=50,1<=s<=2000,1<=e<=200000) Indicate the number of planets, the number of space-transmitting devices, the current time, and the number of space-transmitting devices, respectively. Next m lines, 4 positive integers per line a_i,b_i,c_i,d_i (1<=a_i,b_i,c_i,d_i<=2000), describe the parameters of each device in turn. The next E line, 3 positive integers per line u_i,v_i,w_i (1<=u_i,v_i<=n,u_i!=v_i,1<=w_i<=m) means that from the planet U_i can be transmitted one way to the planet V_i using the w_i plant. output outputs n-1 lines, one integer per line, and line I represents the minimum time required from 1 to i+1, if no solution output-1. Sample Input 3 2 1 3
1 1 5 1
2 2 7 1
1 2 1
2 3 2
3 1 1 Sample Output 3
6

HINT
1 to 3: At the moment 1 the first device is transmitted from 1 to 2, which takes time 3, Waits 2 unit time, and at the moment 6 uses the second device to reach 3, which takes time 1.

Although the transfer time of each moment is different, the earlier it is, the sooner it can be delivered (even if it waits for a period of time to teleport). This translates into a shortest-circuit problem.

It is necessary to pre-f[i][j], the minimum time required to transmit the first transmission device at J time. Because%CI is required for the next transfer of compute time. So the range of J is in [0,c[i]-1]. Maintain f[i][j] with the minimum value of the prefix and suffix.

Main.cpp//bzoj5047////Created by ZC on 2017/10/17. COPYRIGHT©2017 year ZC.
All rights reserved. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <
algorithm> #include <vector> #include <queue> using namespace std;
const int inf=0x3f3f3f3f;
const int m=55;
const int s=2200;
int n,m,ss,ee;


int a[m],b[m],c[m],f[m][s*2];
    Template <class t> bool Read (T &ret) {char C;
    int sgn;
    T bit = 0.1;
    if (C=getchar (), c==eof) {return 0;
    } while (c! = '-' && c! = ') ' && (C < ' 0 ' | | c > ' 9 ')) {c = GetChar (); } SGN = (c = = '-')?
    -1:1; ret = (c = = '-')?
    0: (C-' 0 ');
    while (c = GetChar (), C >= ' 0 ' && C <= ' 9 ') {ret = ret * + (C-' 0 ');
        } if (c = = "| | c = = ' \ n ') {ret *= sgn;
    return 1;
    } while (c = GetChar (), C >= ' 0 ' && C <= ' 9 '){ret + = (c-' 0 ') * bit, bit/= 10;
    } ret *= sgn;
return 1;
} const int maxn=100000+5;
    struct edge{int from,to,weight;
Edge (int from,int to,int weight): From, to, weight (weight) {}};   struct heapnode{//prority_queue in the priority int u,dist;  Dist:u point to start of shortest path, u: End of Heapnode (int u,int D): U (U), dist (d) {} BOOL operator < (const heapnode& h) const
    {return dist>h.dist;
}
};
    struct dijkstra{//packaged in Dijkstra int n,m;
    Vector<edge> edges;
    Vector<int> G[MAXN];
    BOOL DONE[MAXN];
    int DIST[MAXN];
    int P[MAXN];
        Dijkstra (int n): N (n) {for (int i=0;i<n;i++) g[i].clear ();
    Edges.clear ();
        } void Addedge (int from,int to,int weight) {edges.push_back (Edge (from,to,weight));
        M=edges.size ();  G[from].push_back (m-1);
        Save from departure side} void Dijkstra (int s) {priority_queue

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.