Hungry. In fact, I am not too fond of blogging people pull, because I think a little bit of waste of time, especially online can find the puzzle, but also lazy to write a blog
But I wrote down the question. Blog
Because since this year CCCC competition has been preparing Waterloo Cup, yesterday Waterloo Cup just finished, today want to rest, also a bit boring
and Waterloo Cup because the basic not to test this kind of diagram, so Dijkstra these also basically did not review, lead CCCC to now three weeks, I am bored to open my pat on the submit code found himself incredibly a bit do not understand oneself write this problem = = also own a thought
And the problem on the net is basically sticky code on the matter, but also to review their own code, nonsense said a little bit more, the following or sticky questions and problems
Topic Jump Links
l2-001. Emergency rescue time limit ms
Memory Limit 65536 KB
Code length limit 8000 B
Standard author Chen Yue The procedure of the sentence
As the head of a city emergency rescue team, you have a special map of the country. The map shows a number of scattered cities and a number of fast roads connecting the cities. The number of rescue teams in each city and the length of each fast path connecting two cities are marked on the map. When other cities have emergency calls for you, your job is to lead your rescue team to the scene as quickly as possible, and to summon as many rescue teams along the way.
Input Format:
Enter the first row gives 4 positive integers n, m, S, D, where N (2<=n<=500) is the number of cities, by the way assume the city's number is 0~ (N-1), M is the number of fast roads, S is the city number of the departure, D is the city number of the destination. The second line gives n positive integers, of which the number I is the rescue team for the first city, and the number is separated by a space. In the following m lines, each row gives a quick path to the information: City 1, City 2, the length of the fast road, separated by spaces in between, numbers are integers and no more than 500. The input guarantees that the rescue is feasible and the best solution is unique.
output Format:
The first line outputs the number of bars with different shortest paths and the number of rescue teams that can be summoned. The second line outputs the city number that passes through the path from S to D. The number is separated by a space, the output can not have extra space. Input Sample:
4 5 0 3 0 1 1 1 3 2 0 3 3 0 2 2 2 3 2
Output Sample:
2
0 1 3
In fact, this problem is a dijkstra of all to consider the deformation, but also very much in line with the CCCC like to test the style of data structure (but this year seems to have no data structure of the problem = =)
Consider the fact that the boundary value is the smallest, in the same case the value of the maximum value, and then consider a few paths to this side value is the same as the smallest, while recording the path
Below my code, because I am the school room to write the submission, now in the dormitory copy down added a note, so indented into two spaces = = Harmless
#include <iostream> #include <vector> #include <cstring> #include <set> #include <algorithm
> #include <stack> using namespace std; int Road[501][501],last[501],people[501],human[501],walk[501],rewalk[501];//road represents the distance of two cities last represents what the previous road of the current city is, Used to finally output the shortest path people indicates how many people there were in that city. Human indicates how many individuals the city can gather from the beginning to the present how much personal int main ()//walk indicates from the beginning to the current City shortest path is how much ReWalk representation from the beginning
The shortest path to the present city has several {int n,m,s,d;
Memset (Road,-1,sizeof (road));
Set<int> Vis;
cin>>n>>m>>s>>d;
int Tmpi;
for (int i=0;i<n;i++) {cin>>tmpi;
People[i]=tmpi;
Human[i]=tmpi;
Vis.insert (i);
WALK[I]=0X7FFFFFFF;
} last[s]=-1;
walk[s]=0;
Rewalk[s]=1;
for (int i=0;i<m;i++) {int be,en;
cin>>be>>en;
cin>>road[be][en];
Road[en][be]=road[be][en];
}//This is the initialization data for (int now=s;vis.size () >0;vis.erase (now))//traversal of all cities {int min=0x7fffffff;
for (int i=0;i<n;i++)//each selection and the shortest path in the current city adjacent to the city {if (Walk[i]<min&&vis.count (i) ==1) {now=i;
Min=walk[i]; } for (int i=now,j=0;j<n;j++) {if (road[i][j]!=-1) {if (Walk[j]>road[i][j]+walk[now
]//distance is preferred, if the distance near the priority update data {Walk[j]=road[i][j]+walk[now];
Last[j]=now;
Human[j]=people[j]+human[now];
Rewalk[j]=rewalk[now]; else if (Walk[j]==road[i][j]+walk[now])//If the distance is equal, the current number of scenarios to +1 if the number is more than before the number of updates and where the data {Rewal
K[j]+=rewalk[now];
if (Human[j]<people[j]+human[now]) {last[j]=now;
Human[j]=people[j]+human[now];
}}}} cout<<rewalk[d]<< "" <