Pat Ladder Race-l2-001 Emergency rescue

Source: Internet
Author: User
Tags int size
<pre name= "code" class= "CPP" > #include <iostream> #include <fstream> #include <cstring> #
include<vector> #include <string> #include <cstdio> using namespace std;
const int size=500;
const int inf=0x3f3f3f3f;
Input list int n,m,s,d;
temporary variables int i,j,t;
Auxiliary vector vector<int>rescueteamnum;//do not think that the vector than the array with the use of the problem of the different bar int matrix[size][size];
int visited[size];
int dis[size];
int path[size];
int largestteamnum[size];

int pathnum[size]; void Shortestpath_dij (int v0) {//********************initialize code******************** memset (visited,0,sizeof
    (visited));
    LARGESTTEAMNUM[V0]=RESCUETEAMNUM[V0];
        for (i=0; i<n; i++) {dis[i]=matrix[v0][i];

        Path[i]=-1;
            if (dis[i]<inf) {pathnum[i]=1;
            Path[i]=v0;
            if (i!=v0) largestteamnum[i]=rescueteamnum[i]+rescueteamnum[v0];
 cout<<i<< "" <<LargestTeamNum[i]<<endl;       }}//for (i=0; i<n; i++)//cout<<largestteamnum[i]<<endl;
    cout<<endl;
    Path[s]=-1;
    Visited[v0]=1;
    int Min;
    int thenearest;
        Main circle******************** for (j=1; j<n; J + +) {//remaining N-1 points min=inf; for (i=0; i<n; i++)//Find the closest point to V0 if (!
                Visited[i]&&dis[i]<min) {min=dis[i];
            thenearest=i; } visited[thenearest]=1;
        Add the nearest point to the set of shortest paths to//largestteamnum[thenearest]+=largestteamnum[path[thenearest]]; for (i=0; i<n; i++)//update other points in the collection of the shortest path that are not joined to the v0 distance if (!
                Visited[i]&&min+matrix[thenearest][i]<dis[i]) {dis[i]=min+matrix[thenearest][i];
                Path[i]=thenearest;
                Largestteamnum[i]=largestteamnum[thenearest]+rescueteamnum[i];
            Pathnum[i]=pathnum[thenearest]; } else if (!
                Visited[i]&&min+matrix[thenearest][i]==dis[i]) {pathnum[i]+=pathnum[thenearest];
                    if (Largestteamnum[i] < largestteamnum[thenearest]+rescueteamnum[i]) {
                    Largestteamnum[i]=largestteamnum[thenearest]+rescueteamnum[i];
                Path[i]=thenearest;
        }}}//for} void Printpath (int D)//Good recursive {if (path[d]!=-1) {Printpath (path[d]);
    cout<<path[d]<< "";
    }} int main () {ifstream cin ("In.txt");
        while (cin>>n>>m>>s>>d) {rescueteamnum.clear ();
            for (i=0; i<n; i++) {cin>>j;
        Rescueteamnum.push_back (j);
        } memset (Matrix,inf,sizeof (Matrix));
        int C1,c2,len;
            for (i=0; i<m; i++) {cin>>c1>>c2>>len;
        Matrix[c1][c2]=matrix[c2][c1]=len;
        }matrix[s][s]=0;
Shortestpath_dij (S);
for (i=0; i<n; i++)//cout<<dis[i]<< "" <<Path[i]<<endl;


        cout<<endl;
        cout<<pathnum[d]<< "" <<LargestTeamNum[D]<<endl;
        Printpath (D);
    cout<<d<<endl;
}//while return 0; }


Long time no update

I'm a graduate.

Just practice the data structure ...

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.