STANAANDREY

adj->inc

Feb 15th, 2021 (edited)
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define NMAX 103
  4. int n, m, top = 1;
  5. bool a[NMAX][NMAX];
  6. int inc[NMAX][NMAX], last;
  7.  
  8. void read() {
  9.     cin >> n >> m;
  10.     for (int i = 0; i < m; i++) {
  11.         int x, y;
  12.         cin >> x >> y;
  13.         a[x][y] = true;
  14.     }
  15. }
  16.  
  17. void solve() {
  18.     for (int i = 1; i <= n; i++) {
  19.         for (int j = 1; j <= n; j++) {
  20.             if (a[i][j]) {
  21.                 last++;
  22.                 inc[i][last] = 1;
  23.                 inc[j][last] = -1;
  24.             }
  25.         }
  26.     }
  27. }
  28.  
  29. void write() {
  30.     for (int i = 1; i <= n; i++) {
  31.         for (int j = 1; j <= m; j++) {
  32.             cout << inc[i][j] << ' ';
  33.         }
  34.         cout << endl;
  35.     }
  36. }
  37.  
  38. int main() {
  39.     read();
  40.     solve();
  41.     write();
  42.     return 0;
  43. }
  44.  
Add Comment
Please, Sign In to add comment