-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro.cpp
68 lines (65 loc) · 1.28 KB
/
intro.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
#include <iostream>
#include <cmath>
#include <stack>
#include <cstring>
#include <stdlib.h>
#include <unordered_set>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <queue>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define pii vector<int, int>
#define vii vector<pii>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define ss second
const int N = 1e5 + 2;
vi adj[N];
/*
adjacency matrix
adjacency list
dfs bfs
dfs in post pre
implemented using stacks
bfs queue
tree edges=n-1
*/
int main()
{
int n = 7, m = 7;
// vvi adjm(n+1,vi(n+1,0));
// rep(i,0,m){
// int x,y;
// cin>>x>>y;
// adjm[x][y]=1;
// adjm[y][x]=1;
// }
// rep(i,1,n+1){
// rep(j,1,n+1){
// cout<<adjm[i][j]<<" ";
// }
// cout<<endl;
// }
rep(i, 0, m)
{
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
rep(i, 1, n + 1)
{
cout << i << "->";
vi::iterator it;
for (it = adj[i].begin(); it != adj[i].end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
}