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]>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; }