File tree Expand file tree Collapse file tree 2 files changed +76
-0
lines changed Expand file tree Collapse file tree 2 files changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+
5
+ void printGraph (vector<int > adj[], int V)
6
+ {
7
+ for (int i=0 ;i<V;i++)
8
+ {
9
+ cout<<i;
10
+ for (int j=0 ;j< adj[i].size ();j++)
11
+ {
12
+ cout<<" -> " <<adj[i][j];
13
+ }
14
+ cout<<endl;
15
+ }
16
+ // Your code here
17
+ }
18
+
19
+
20
+ // Position this line where user code will be pasted.
21
+ int main ()
22
+ {
23
+ int t;
24
+ cin>>t;
25
+ while (t--)
26
+ { int v, e;
27
+ cin>>v>>e;
28
+ int a, b;
29
+ vector<int > adj[v];
30
+ for (int i=0 ;i<e;i++)
31
+ {
32
+ cin>>a>>b;
33
+ adj[a].push_back (b);
34
+ adj[b].push_back (a);
35
+ }
36
+ printGraph (adj, v);
37
+
38
+ }
39
+ return 0 ;
40
+ }
41
+
42
+
43
+ /* This is a function problem.You only need to complete the function given below*/
44
+ // The Graph structure is as folows
45
+ // Function to print graph
46
+ // adj: array of vectors to represent graph
47
+ // V: number of vertices
48
+
49
+
50
+
51
+ /* Input:
52
+ 8 14
53
+ 0 3
54
+ 0 1
55
+ 1 2
56
+ 1 4
57
+ 1 5
58
+ 1 3
59
+ 2 6
60
+ 2 4
61
+ 4 7
62
+ 5 6
63
+ 5 2
64
+ 5 3
65
+ 5 7
66
+ 7 1
67
+
68
+ Its Correct output is:
69
+ 0-> 3-> 1
70
+ 1-> 0-> 2-> 4-> 5-> 3-> 7
71
+ 2-> 1-> 6-> 4-> 5
72
+ 3-> 0-> 1-> 5
73
+ 4-> 1-> 2-> 7
74
+ 5-> 1-> 6-> 2-> 3-> 7
75
+ 6-> 2-> 5
76
+ 7-> 4-> 5-> 1 */
You can’t perform that action at this time.
0 commit comments