-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrafo.cpp
More file actions
46 lines (31 loc) · 730 Bytes
/
Grafo.cpp
File metadata and controls
46 lines (31 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*Ejercicios de Grafos*/
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
/*Declaro los vertices y aristas*/
int n;
int m;
int x, y;
/*Leo los vertices y aristas*/
cin >> n >> m;
// Declaro Matriz de Adyacencia
vector< vector<int> > G(n);
// Leo el Grafo por la Consola
for (int i = 0; i < m; ++i) {
cin >> x >> y; // Leo arista (x,y)
G[x].push_back(y);
G[y].push_back(x);
}
// Imprimir el Grafo G(n) por la Consola
for (int i = 0; i < n; i++) {
cout << "Vertices adyacentes a " << i << ": ";
for (int j = 0; j < G[i].size(); j++){
cout << G[i][j] << ' ';
}
cout << endl;
}
return 0;
}