Advertisement
STANAANDREY

grade graf orientat cls

Feb 9th, 2021
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define NMAX 103
  4. int n, m;
  5. bool adjm[NMAX][NMAX];
  6. int d[NMAX][2];
  7.  
  8. void read() {
  9.     cin >> n >> m;
  10.     for (int i = 0; i < m; i++) {
  11.         int a, b;
  12.         cin >> a >> b;
  13.         adjm[a][b] = 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 (adjm[i][j]) {
  21.                 d[i][0]++;
  22.                 d[j][1]++;
  23.             }
  24.         }
  25.     }
  26. }
  27.  
  28. void write() {
  29.     for (int sign = 0; sign < 2; sign++) {
  30.         for (int i = 1; i <= n; i++) {
  31.             cout << 'd' << (sign ? '-' : '+') << '(' << i << ")=" << d[i][sign] << endl;
  32.         }
  33.     }
  34. }
  35.  
  36. int main() {
  37.     read();
  38.     solve();
  39.     write();
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement