Advertisement
Guest User

Prob 9

a guest
Feb 29th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. int a[100][100],s,n,m,h[100];
  6. void citire()
  7. {
  8.     ifstream fin("graf.in");
  9.     fin>>n>>m>>s;
  10.     for(int i=1;i<=m;i++)
  11.     {
  12.         int x,y;
  13.         fin>>x>>y;
  14.         a[x][y]=1;
  15.         a[y][x]=1;
  16.     }
  17.     for(int i=1;i<=n;i++)
  18.         fin>>h[i];
  19. }
  20. int main()
  21. {
  22.     citire();
  23.     for(int i=1;i<=n;i++)
  24.     {
  25.         if(i==s)
  26.         {
  27.             for(int j=1;j<=n;j++)
  28.                 {
  29.                     if(a[i][j]==1 && h[i]<=h[j])
  30.                     {
  31.                     cout<<j<<" camera inundata "<<i<<" "<<j<<" culoar umezit ";
  32.                         for(int k=s+1;k<=n;k++)
  33.                         {
  34.                             if(a[j][k]==1 && h[j]<=h[k])
  35.                                 {
  36.                                     cout<<k<<" camera inundata "<<j<<" "<<k<<" culoar umezit ";
  37.                                     cout<<endl;
  38.                                 }
  39.                                 cout<<endl;
  40.                         }
  41.                     }
  42.                     cout<<endl;
  43.  
  44.                 }
  45.  
  46.         }
  47.     }
  48.     return 0;
  49. }
  50.  
  51. 6 6 3
  52. 1 2
  53. 2 3
  54. 3 4
  55. 3 5
  56. 4 5
  57. 3 6
  58. 3 6 4 7 1 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement