#include #include using namespace std; bool checkRow(vector> &m, int row, int currIndex, int size) { for (int i = 0; i < size; ++i) if (i != currIndex && m[row][i] == 1) return true; return false; } bool checkColumn(vector> &m, int col, int currIndex, int size) { for (int i = 0; i < size; ++i) if (i != currIndex && m[i][col] == 1) return true; return false; } int main() { int result = 0; int nodes, pipes; cin >> nodes >> pipes; int temp_src, temp_dest; vector> m; m.reserve(nodes); for (int i = 0; i < nodes; ++i) { m[i].reserve(nodes); } while (cin >> temp_src >> temp_dest ){ m[temp_src - 1][temp_dest - 1] = 1; } // for (int i = 0; i < nodes; ++i) { // for (int j = 0; j < nodes; ++j) { // cout << m[i][j] << " "; // } // cout << endl; // } for (int i = nodes - 1; i >= 0; --i) { for (int j = 0; j < nodes; ++j) { // cout << "i: " << i << ", j:" << j << endl; // cout << checkRow(m, i, j) << " " << checkColumn(m, j, i) << endl; if (m[i][j] == 1 && checkRow(m, i, j, nodes) && checkColumn(m, j, i, nodes)) { // cout << "syka" << endl; result++; m[i][j] = 2; // for (int i = 0; i < nodes; ++i) { // for (int j = 0; j < nodes; ++j) { // cout << m[i][j] << " "; // } // cout << endl; // } // cout << endl; } } } cout << result << endl; return 0; }