POJ 1502:mpi Maelstrom

Source: Internet
Author: User

The main idea is that there is a message to be sent from the first processor to the remaining individual processors, for the longest time required.


Compare the basic shortest-circuit problem, SPFA once over. However, this problem data gives a strange way, it gives a lower triangular matrix, and does not give the main diagonal data. The data on the diagonal is recorded as 0 by test instructions, and then the matrix is symmetric about the main diagonal. There is a character x in the data, which means that it cannot be communicated. In this case, the method of scanf ("%s", ch) +atoi (CH) can be solved.


Code:

#include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #include <iostream&
Gt


using namespace Std;
const int inf=0x3f3f3f3f;
int n;
int mm[105][105]={0};
int dis[105]={0};
BOOL Had[105]={0};


Queue <int> q;
    void Spfa () {memset (dis,0x3f,sizeof (dis));
    Memset (Had,0,sizeof (had));
    Dis[0]=0;q.push (0);
        while (!q.empty ()) {int T=q.front (); Q.pop ();
        had[t]=0; for (int i=0;i<n;i++) {if (Mm[t][i]!=inf && dis[i]>dis[t]+mm[t][i]) {dis[i]=dis[t]
                +mm[t][i];
                    if (!had[i]) {had[i]=1;
                Q.push (i);
    }}}}} int main () {cin>>n;
            for (int i=1;i<n;i++) {for (int j=0;j<i;j++) {char ch[20];
            scanf ("%s", ch);
            if (ch[0]== ' x ') Mm[i][j]=mm[j][i]=inf;
        else Mm[i][j]=mm[j][i]=atoi (CH);
    }} SPFA (); int ans= 0;
    for (int i=0;i<n;i++) {if (Dis[i]>ans) ans=dis[i];
    } cout<<ans<<endl;
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.