HDU1869 Six degree separation (Dijkstra algorithm)

Source: Internet
Author: User
Tags min

This is the simple transformation of the Dijkstra algorithm, according to the template can write the topic of the AC code, I hope you can understand the importance of the template
below is the slag of the AC code.

#include <cstdio> #include <cstring> #include <iostream> #define INF 0x3fffffff #define N 205 using

namespace Std;

int e[n][n],n,m,book[n],dis[n];
    int Dijkstra (int s) {int i,j,u,min;
    memset (book,0,sizeof (book));
    for (i=0;i<n;i++) {dis[i]=inf;

    } dis[s]=0;
        for (i=1;i<=n;i++) {u=-1;
        Min=inf;
                for (j=0;j<n;j++) {if (min>dis[j]&&book[j]==0) {u=j;
            MIN=DIS[J]; }} if (u==-1| |
        DIS[U]&GT;7) break;
        Book[u]=1; for (j=0;j<n;j++) {if (Book[j]==0&&dis[j]>dis[u]+e[u][j]) {D
            IS[J]=DIS[U]+E[U][J];
    }}} if (i<=n) {return 0;
} else return 1; } int main () {while (scanf ("%d%d", &n,&m)!=-1) {for (int. i=0;i<n;i++) {for
        (int j=0;j<n;j++)    {E[i][j]=inf;
        }} int x, y;
            for (int i=0;i<m;i++) {scanf ("%d%d", &x,&y);
            if (x!=y) {e[x][y]=e[y][x]=1;
        }} int flag=0;
            for (int i=0;i<n;i++) {if (Dijkstra (i) ==0) break;
        flag++;
        } if (flag<n) cout<< "No" <<endl;
    else cout<< "Yes" <<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.