HDU 4849-wow! Such city! (Shortest way)

Source: Internet
Author: User

wow! Such city!Time limit:15000/8000 MS (java/others) Memory limit:102400/102400 K (java/others)
Total submission (s): 824 Accepted Submission (s): 310


Problem Descriptiondoge, tired of being a popular image on Internet, are considering moving to another city for a new-to-A-O F Life.
In his country there is N (2≤n≤1000) cities labeled 0 ... N-1. He is currently in the city 0. Meanwhile, for each pair of cities, there exists a road connecting them, costing Ci,j (a positive integer) for traveling F Rom City i to City J. Please note this ci,j may not be equal to cj,i for any given i≠j.
Doge is carefully examining the cities:in fact he would divide cities (his current city 0 is notIncluded) into M (2≤m≤106) categories as follow:if the minimal cost from he current city (labeled 0) to the city I I S Di, city I belongs to category numbered Di MoD M. Doge wants to know the ' minimal ' category (a category with minimal number) which contains at least one city.
For example, for a country with 4 cities (labeled 0 ... 3, note that city 0 are not considered), Doge wants to divide them into 3 categories. Suppose category 0 contains no city, Category 1 contains City 2 and 3, while category 2 contains City 1, Doge consider cat Egory 1 as the minimal one.
Could Doge solve this problem?



Note:

Ci,j is generated in the following to:
Given integers X0, X1, Y0, Y1, (1≤x0, X1, Y0, y1≤1234567), for k≥2 we have
Xk = (12345 + Xk-1 * 23456 + Xk-2 * 34567 + Xk-1 * Xk-2 * 45678) mod 5837501
Yk = (56789 + Yk-1 * 67890 + Yk-2 * 78901 + Yk-1 * Yk-2 * 89012) mod 9860381
The For k≥0 we have

Zk = (Xk * 90123 + Yk) mod 8475871 + 1

Finally for 0≤i, j≤n-1 we have

Ci,j = Zi*n+j for i≠j
Ci,j = 0 for i = j

Inputthere is several test cases. Please process till EOF.
For each test case, the there is only one line containing 6 integers n,m,x0,x1,y0,y1. See the description for more details.
Outputfor each test case, output a single line containing a single integer:the number of minimal category.
Sample Input

3 10 1 2 3 44 20 2 3 4 5

Sample Output
110 first time to encounter the shortest problem of the area race.

Although it is not the shortest path (it is almost the same.) The weights are generated by a recursive formula (given in the title), and then run over Dijkstra, starting at 1, to find the minimum value of the dis[i]%m. Weights note beyond the int range to use LLD

#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include < Algorithm> #define INF 0x3f3f3f3f#define ll long longusing namespace Std;ll dis[1010],v[1010];ll map[1010][1010];int    X0,x1,y0,y1,n,m;void Dijkstra () {int minx,k=0;        for (int i=0; i<=n; i++) {dis[i]=map[0][i];;    v[i]=0;    } dis[0]=0;        for (int j=0; j<n; J + +) {Minx=inf;                 for (int i=0; i<n; i++) {if (V[i]==0&&minx>dis[i]) {minx=dis[i];            K=i;        }} v[k]=1;                for (int i=0; i<n; i++) {if (V[i]==0&&dis[i]>dis[k]+map[k][i]) {            Dis[i]=dis[k]+map[k][i]; }}} return;} ll Xx[1002000],yy[1002000],zz[1002000];int Main () {while (scanf ("%d%d%d%d%d%d",&n,&m,&x0,&x1,& Y0,&AMP;Y1)!=eof) {for (Int. i=0; i<n; i++) {for (iNT J=0; j<n;            J + +) {Map[i][j]=inf;        } map[i][i]=0;        } xx[0]=x0;xx[1]=x1;        Yy[0]=y0;yy[1]=y1; for (int i=2; i<=n* (n-1) +n; i++) {xx[i]= (12345+xx[i-1]*23456+xx[i-2]*34567+xx[i-1]*xx[i-2]*45678)%583            7501;        yy[i]= (56789+yy[i-1]*67890+yy[i-2]*78901+yy[i-1]*yy[i-2]*89012)%9860381;        } for (int i=0; i<=n* (n-1) +n; i++) {zz[i]= (xx[i]*90123+yy[i])%8475871+1;                    } for (int i=0, i<n; i++) {for (int j=0; j<n; J + +) {if (i==j)                map[i][j]=0;            else Map[i][j]=zz[i*n+j];        }} Dijkstra ();        ll Minn=inf;        for (int i=1; i<n; i++) {minn=min (minn,dis[i]%m);    } printf ("%lld\n", Minn); } return 0;}



HDU 4849-wow! Such city! (Shortest way)

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.