forked from sakshamchecker/Hacktoberfest-21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdjacency Matrix_Graph.cpp
71 lines (71 loc) · 1.53 KB
/
Adjacency Matrix_Graph.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//************************** it's all about practice ***********************
#include<bits/stdc++.h>
using namespace std;
//**** Abbreviation ****
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//**** STL ****
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define mp make_pair
#define ALL(x) x.begin(), x.end()
//**** some I/O ****
#define no cout << "NO\n"
#define yes cout << "YES\n"
//**** Fast I/O ****
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//**** Short Code ****
#define tc ll t;cin>>t;while(t--)
#define f(i,a,b) for(ll i=a;i<b;i++)
/*---------------------------------------------------------------------------*/
vector<vector<int>> addEdge(vector<vector<int>> &graph,ll v1,ll v2)
{
graph[v1-1][v2-1]=1;
graph[v2-1][v1-1]=1;
return graph;
}
vector<vector<int>> graph(ll v,ll e)
{
vector<vector<int>> gr;
gr.reserve(v);
f(i,0,v)
{
vector<int> temp;
temp.reserve(v);
f(j,0,v)
temp.pb(0);
gr.pb(temp);
}
f(i,0,e)
{
int v1,v2;
cin>>v1>>v2;
gr=addEdge(gr,v1,v2);
}
return gr;
}
void print(vector<vector<int>> &graph,ll v,ll e)
{
f(i,0,v)
{
f(j,0,graph[i].size())
{
cout<<graph[i][j]<<" ";
}
cout<<"\n";
}
}
int main()
{
FAST_IO
ll v,e;// number of vertices and number of edges
cin>>v>>e;
vector<vector<int>> gr=graph(v,e);
print(gr,v,e);
return 0;
}