Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int n; cin >> n;
- // Матрица смежности.
- vector<vector<bool>> matrix(n, vector<bool>(n));
- for (auto& row : matrix) {
- for (int j = 0; j < n; ++j) {
- bool x; cin >> x;
- row[j] = x;
- }
- }
- // Список смежности.
- vector<vector<int>> g(n);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (matrix[i][j]) {
- g[i].push_back(j);
- }
- }
- }
- for (int u = 0; u < n; ++u) {
- cout << u + 1 << ": ";
- for (int v : g[u]) cout << v + 1 << ", ";
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement