1. 程式人生 > >圖與樹基礎-完全圖的判定

圖與樹基礎-完全圖的判定

鄰接矩陣 bsp nbsp pre style ostream color for col

https://www.jisuanke.com/course/2148/162483

 1 #include<iostream>
 2 using namespace std;
 3 //稠密圖用鄰接矩陣
 4 int a[105][105];
 5 int main()
 6 {
 7     int n,m;
 8     int x,y;
 9     cin>>n>>m;
10     for(int i=0;i<m;i++)
11     {
12         cin>>x>>y;
13         a[x][y]=a[y][x]=1
; 14 } 15 for(int i=1;i<=n;i++)//註意下表從1開始,1~n 16 for(int j=1;j<=n;j++) 17 { 18 if(i!=j) 19 { 20 if(a[i][j]==0) 21 { 22 cout<<i<<" "<<j<<endl; 23 cout<<"No"; 24 return
0; 25 } 26 } 27 } 28 cout<<"Yes"; 29 return 0; 30 }

圖與樹基礎-完全圖的判定