Advertisement
uchihamadara3

grafuri egale

Jan 15th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. /**
  6. se dau 2 grafuri neorientate prin lista muchiilor in 2 fisiere.
  7. stabiliti daca cele doua grafuri sunt identice
  8. (acelasi nr de vf si ac muchii)
  9. */
  10. ifstream fin("graf1.in");
  11. ifstream fin1("graf2.in");
  12. //ofstream fout("reuniune.out");
  13. //ofstream fout1("intersectie.out");
  14.  
  15. /// 4/175 manulal
  16.  
  17. int n1, n2;
  18. int a[101][101], b[101][101];
  19.  
  20. int main()
  21. {
  22.     fin>>n1; fin1>>n2;
  23.     if(n1!=n2) {cout<<"NU"; return 0;}
  24.     int x, y;
  25.     while(fin>>x>>y) a[x][y] = a[y][x] = 1;
  26.     while(fin1>>x>>y) b[x][y] = b[y][x] = 1;
  27.  
  28.     for(int i=1;i<=n;++i)
  29.         for(int j=1;j<=n;++j)
  30.             if(a[i][j] != b[i][j])
  31.             {
  32.                 cout<<"NU";
  33.                 return 0;
  34.             }
  35.     cout<<"DA";
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement