STANAANDREY

pb 3/2/2021

Mar 2nd, 2021 (edited)
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define NMAX 103
  4. int n, m;
  5. int ad[NMAX][NMAX], roy[NMAX][NMAX];
  6.  
  7. void read() {
  8.     cin >> n >> m;
  9.     for (int i = 0; i < m; i++) {
  10.         int a, b;
  11.         cin >> a >> b;
  12.         ad[a][b] = 1;
  13.     }
  14. }
  15.  
  16. void RoyWarshall() {
  17.     for  (int k = 1; k <= n; k++) {
  18.         for (int i = 1; i <= n; i++) {
  19.             for (int j = 1; j <= n; j++) {
  20.                 if (!roy[i][j]) {
  21.                     roy[i][j] = roy[i][k] * roy[k][j];
  22.                 }
  23.             }
  24.         }
  25.     }//*/
  26. }
  27.  
  28. void solveA() {
  29.  
  30.     cout << "1.Exista circuit:";
  31.     for (int i = 1; i <= n; i++) {
  32.         if (roy[i][i]) {
  33.             cout << "DA" << endl;
  34.             return;
  35.         }
  36.     }
  37.     cout << "NU" << endl;
  38. }
  39.  
  40. void solveB() {
  41.     cout << "varfurile intre care nu exista drumuri:" << endl;
  42.     for (int i = 1; i <= n; i++) {
  43.         for (int j = 1; j <= n; j++) {
  44.             if (!roy[i][j]) {
  45.                 cout << i << '-' << j << endl;
  46.             }
  47.         }
  48.     }
  49. }
  50.  
  51. void solveC() {
  52.     bool ok = true;
  53.     for (int i = 1; i <= n && ok; i++) {
  54.         for (int j = i + 1; j <= n && ok; j++) {
  55.             if ((ad[i][j] && ad[j][i]) || (!ad[i][j] && !ad[j][i])) {
  56.                 ok = false;
  57.             }
  58.         }
  59.     }
  60.     if (!ok) {
  61.         cout << "nu ";
  62.     }
  63.     cout << "e turneu!" << endl;
  64. }
  65.  
  66. void solveD() {
  67.     bool ok = true;
  68.     for (int i = 1; i < n && ok; i++) {
  69.         for (int j = i + 1; j <= n && ok; j++) {
  70.             if (!ad[i][j] && !ad[j][i]) {
  71.                 ok = false;
  72.             }
  73.         }
  74.     }
  75.     if (!ok) {
  76.         cout << "nu ";
  77.     }
  78.     cout << "e complet!" << endl;
  79. }
  80.  
  81. int main() {
  82.     read();
  83.     memcpy(roy, ad, sizeof ad);
  84.     RoyWarshall();
  85.     solveA();
  86.     solveB();
  87.     solveC();
  88.     solveD();
  89.     return 0;
  90. }
  91.  
Add Comment
Please, Sign In to add comment