-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedge_list.cpp
73 lines (62 loc) · 1.63 KB
/
edge_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
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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE
#define __elshorpagi__ (ios_base::sync_with_stdio(false), cin.tie(NULL))
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define edl '\n'
/*----Problem #1: Edge List Representation--------------------*/
struct Edge
{
int from, to, weight;
Edge(int from, int to, int weight) : from(from), to(to), weight(weight) {}
bool operator<(const Edge &e) const
{
return weight < e.weight;
}
void print()
{
cout << "Edge (" << from << " " << to << " " << weight << ")" << edl;
}
};
typedef vector<Edge> GRAPH;
void add_edge_list_reper(GRAPH &graph, int from, int to, int weight)
{
graph.push_back({from, to, weight});
}
void print_adjaceny_edge_list(GRAPH &graph)
{
int len(sz(graph));
for (int e(0); e < len; ++e)
graph[e].print();
}
void Solve()
{
// this representation in general is slower representation
// and it's has very limited usege, but it's very simple
int nodes, edges;
cin >> nodes >> edges;
GRAPH graph;
for (int e(0); e < edges; ++e)
{
int from, to, weight;
cin >> from >> to >> weight;
add_edge_list_reper(graph, from, to, weight);
}
sort(all(graph)); // sort depend on the operator overloading;
print_adjaceny_edge_list(graph);
cout << edl << "DONE" << edl;
}
int main()
{
__elshorpagi__;
freopen("../test/input.txt", "r", stdin);
freopen("../test/output.txt", "w", stdout);
int tc(1);
// cin >> tc;
while (tc--)
Solve();
return (0);
}