-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdj list.cpp
52 lines (33 loc) · 949 Bytes
/
Adj list.cpp
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
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
//benifit of list is space otimization O(v+e)-->here v is vertices and e is edges
//maximum edegs in a graph is v^2 edges -->higher then constantes...!!
const int N =1e3;
//global variable is already 0
int graph [N][N];
//make n vectors...!!
vector<int>graph2[N];
int main()
{
int n,m;
cin>>n;
cin>>m;
int graph[n+1] [n+1];
for(int i=0;i<m;i++)
{
int v1,v2;
cin>>v1;
cin>>v2;
graph [v1] [v2] = 1;
graph [v2] [v1] = 1;
//MAKING LIST>>>
//kon kon kisse connected hai code-->>
//and here v1 vali list mai v2 ko dalna
graph2[v1].push_back(v2);
//and v2 vali list mai v1 vale ko dalna
graph2[v2].push_back(v1);
}
//adj list space complexty is
//O(n+m)
//N = 10^5
}