-
Notifications
You must be signed in to change notification settings - Fork 0
/
anki.cpp
105 lines (91 loc) · 2.05 KB
/
anki.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <vector>
#include <unordered_map>
#include <string>
#include <queue>
#include <iostream>
#include <algorithm>
#include <stack>
#include <numeric>
#include <math.h>
#include <set>
#include <bits/stdc++.h>
#include <bitset>
using namespace std;
template <typename T>
void displayVector(vector<T> arr)
{
for (auto x : arr)
cout << x << endl;
}
template <typename T>
void display2DVector(vector<vector<T>> arr)
{
for (int i = 0; i < arr.size(); ++i)
{
for (int j = 0; j < arr[i].size(); ++j)
cout << arr[i][j] << " ";
cout << endl;
}
}
int N = 9;
vector<vector<pair<int, int>>> adj(N + 1);
vector<int> visited(N + 1);
vector<tuple<int, int, int>> edgeListRepresentation(N + 1);
vector<vector<int>> adjacencymatrixRepresentation;
void bfs(int x)
{
queue<int> nextNodes;
nextNodes.push(x);
while (!nextNodes.empty())
{
int top = nextNodes.front();
if (visited[top])
continue;
visited[top] = true;
for (auto u : adj[top])
nextNodes.push(u.first);
}
}
void treeDfs(int current, int previous)
{
for (auto u : adj[current])
{
if (u.first != previous)
treeDfs(u.first, current);
}
}
bool isPrime(int x)
{
for (int i = 1; i * i < x; ++i)
{
if (x % i == 0)
return false;
}
return true;
}
int sumSegmentTreeTopDown(int a, int b, int x, int y, int k)
{
if (a < x || b > y)
return 0;
else if (x <= a && b <= y)
return tree[k];
int d = (a + b) / 2;
return sumSegmentTreeTopDown(a, d, x, y, k * 2) + sumSegmentTreeTopDown(d + 1, b, x, y, k * 2 + 1);
}
int main()
{
edgeListRepresentation.push_back(make_tuple(9, 7, 3));
edgeListRepresentation.push_back(make_tuple(9, 1, 8));
edgeListRepresentation.push_back(make_tuple(7, 1, -6));
edgeListRepresentation.push_back(make_tuple(7, 3, -1));
edgeListRepresentation.push_back(make_tuple(1, 5, 2));
edgeListRepresentation.push_back(make_tuple(3, 5, 4));
adjacencymatrixRepresentation = {
{},
{0, 0, 8, 3, 0, 0},
{0, 0, 0, 0, 0, 2},
{0, 0, 6, 0, 1, 0},
{0, 0, 0, 0, 0, 4},
{}};
return 0;
}