File tree Expand file tree Collapse file tree
Data Structures/Graphs/Representation Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < vector>
3+
4+ using namespace std ;
5+
6+ int main (int argc, char const *argv[])
7+ {
8+ int n, m;
9+ cin >> n >> m;
10+
11+ vector<int > adj_list[n + 1 ];
12+
13+ while (m--)
14+ {
15+ int u, v;
16+ cin >> u >> v;
17+
18+ adj_list[u].push_back (v);
19+ adj_list[v].push_back (u);
20+
21+ }
22+
23+ for (int i=1 ; i<n+1 ; i++) {
24+ for (int j=0 ; j<adj_list[i].size (); j++)
25+ cout << adj_list[i][j] << " " ;
26+ cout << " \n " ;
27+ }
28+
29+ return 0 ;
30+ }
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+
3+ using namespace std ;
4+
5+ int main (int argc, char const *argv[])
6+ {
7+ int n, m;
8+ cin >> n >> m;
9+
10+ int adj[n + 1 ][n + 1 ];
11+
12+ while (m--)
13+ {
14+ int u, v;
15+ cin >> u >> v;
16+ adj[u][v] = 1 ;
17+ adj[v][u] = 1 ;
18+ }
19+ for (int i = 0 ; i < n + 1 ; i++)
20+ {
21+ for (int j = 0 ; j < n + 1 ; j++)
22+ {
23+ cout << adj[i][j] << " \t\t " ;
24+ }
25+ cout << " \n " ;
26+ }
27+ return 0 ;
28+ }
You can’t perform that action at this time.
0 commit comments