forked from Raiyan-sharif/Algorithm-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.cpp
More file actions
61 lines (52 loc) · 874 Bytes
/
graph.cpp
File metadata and controls
61 lines (52 loc) · 874 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000 //maximum node
vector<int>edges[MAX];
vector<int>cost[MAX]; //parallel vector to store costs;
int main()
{
int N,E,i,j=1;
scanf("%d%d",&N,&E);
//int arr[E]={0};
int max=0;
for(i=1;i<=E;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x==y){
edges[x].push_back(y);
//edges[y].push_back(x);
cost[x].push_back(1);
cost[y].push_back(1);
}
else{
edges[x].push_back(y);
edges[y].push_back(x);
cost[x].push_back(1);
cost[y].push_back(1);}
// arr[j]=edges[x][0];
j++;
}
for(int i=1;i<=N;i++)
{
int size=edges[i].size();
printf("%d->",i);
for(int k=0; k <size; ++k)
{
printf("%d ",edges[i][k]);
}
printf("\n");
}
return 0;
}
/*
6 8
1 2
1 4
2 4
2 5
4 5
5 3
3 6
6 6
*/