-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.cpp
More file actions
46 lines (40 loc) · 771 Bytes
/
Copy pathGraph.cpp
File metadata and controls
46 lines (40 loc) · 771 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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,e;
cin>>n>>e;
int arr[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++) arr[i][j]=0;
}
vector<vector<int> >v(n);
int start,end;
for(int i=0;i<e;i++)
{
cin>>start>>end;
arr[start-1][end-1]=1;
arr[end-1][start-1]=1;
v[start-1].push_back(end-1);
v[end-1].push_back(start-1);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
for(int i=0;i<n;i++)
{
cout<<i+1<<" : ";
for(int j=0;j<v[i].size();j++)
{
cout<<v[i][j]+1<<" ";
}
cout<<endl;
}
}