HDU--4043(Graph)

来源:互联网 发布:ubuntu 文件格式 编辑:程序博客网 时间:2024/05/16 03:01

The Meanings Of Problem:

    就是给你一个图,给出了两点之间的最小路径,让你判断这样的原先的图存不存在...要是存在输出边的数目

Subjects Catagories:

   Floyded

Codes:

[cpp] view plaincopyprint?
  1. #pragma warning(disable:4786) 
  2.  
  3. #include<iostream> 
  4. #include<algorithm> 
  5.  
  6. using namespace std; 
  7.  
  8. const int MAXN =101; 
  9.  
  10. typedef struct
  11.  
  12.     int num; 
  13.     int map[MAXN][MAXN]; 
  14. }Graphics; 
  15.  
  16.  
  17. int main(){ 
  18.  
  19.     int nCase; 
  20.     Graphics graphics; 
  21.  
  22.     cin>>nCase; 
  23.  
  24.     for(int i=1;i<=nCase;i++){ 
  25.  
  26.         cin>>graphics.num; 
  27.  
  28.         for(int ii=0;ii<graphics.num;ii++){ 
  29.  
  30.             for(int j=0;j<graphics.num;j++){ 
  31.  
  32.                 cin>>graphics.map[ii][j]; 
  33.             } 
  34.         } 
  35.  
  36.         bool flag = true
  37.  
  38.         int count = 0; 
  39.  
  40.         for(ii=0;ii<graphics.num&&flag;ii++){ 
  41.  
  42.             for(int j=0;j<graphics.num&&flag;j++){ 
  43.  
  44.                 if(ii==j) 
  45.                     continue
  46.  
  47.                 int flag_1 = 0; 
  48.                 for(int k=0;k<graphics.num&&flag;k++){ 
  49.  
  50.                     if(ii==k||j==k) 
  51.                         continue
  52.  
  53.                     if(graphics.map[ii][j]>graphics.map[ii][k]+graphics.map[k][j]){ 
  54.  
  55.                         flag =false
  56.                         break
  57.  
  58.                     }else
  59.  
  60.                         if(graphics.map[ii][j]==graphics.map[ii][k]+graphics.map[k][j]){
  61.  
  62.                             flag_1 = 1; 
  63.                             break
  64.                         } 
  65.                     } 
  66.                 } 
  67.  
  68.                 if(flag_1==0) 
  69.                    count++; 
  70.             } 
  71.         } 
  72.  
  73.  
  74.         if(flag) 
  75.             cout<<"Case "<<i<<":"<<" "<<count<<endl; 
  76.         else 
  77.             cout<<"Case "<<i<<":"<<" "<<"impossible"<<endl; 
  78.     } 
  79.     return 0; 

0 0