-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAdjacency List.cpp
44 lines (44 loc) · 943 Bytes
/
Adjacency 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
#include <iostream>
#include <cmath>
#include <map>
#include <set>
using namespace std;
#define speed() \
ios::sync_with_stdio(false); \
cin.tie(0)
#define piss(name) \
speed(); \
freopen(#name "in.txt","r",stdin); \
freopen(#name "out.txt","w",stdout)
#define int long long
#define umap std::unordered_map
#define ummap std::unordered_multimap
#define uset std::unordered_set
#define umset std::unordered_multiset
#define mmap std::multimap
#define mset std::multiset
struct node{
int id;
set<node*> neis;
};
map<int,node*> mp;
signed main()
{
speed();
int n,m;cin>>n>>m;
for (int i=1;i<=n;i++){
mp[i]=new node{i,{}};
}
while (m--){
int a,b;cin>>a>>b;
mp[a]->neis.insert(mp[b]);
mp[b]->neis.insert(mp[a]);
}
for (int i=1;i<=n;i++){
cout<<mp[i]->neis.size()<<' ';
for (auto it:mp[i]->neis){
cout<<it->id<<' ';
}
cout<<'\n';
}
}