-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
74 lines (56 loc) · 1.54 KB
/
main.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
#include <iostream>
#include <fstream>
#include <set>
#include "Graph2.h"
using namespace std;
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(false);
ifstream infile(argv[1]);
int N;
int M;
infile>>N >> M ;
vector<int> ladder;
vector<vector<int>> adjMatrix;
for(int i = 0 ; i<N-1 ; ++i) {
int ladderr;
for (int k = 0; k < M; ++k) {
infile >> ladderr;
ladder.push_back(ladderr);
vector<int> adjs;
adjs.push_back(i * M + k + M);
if (k < M - 1) {
adjs.push_back(i * M + k + 1);
}
adjMatrix.push_back(adjs);
}
}
for (int k = 0; k < M; ++k) {
int ladderr;
infile >> ladderr;
ladder.push_back(ladderr);
vector<int> adjs;
if (k < M - 1) {
adjs.push_back((N-1) * M + k + 1);
}
adjMatrix.push_back(adjs);
}
Graph2 graph = Graph2(M*N);
for(int i = 0 ; i < M*N; i++){
for(auto k = adjMatrix[i].begin(); k != adjMatrix[i].end();k++){
graph.addEdge(i, *k, abs(ladder[i] - ladder[*k]));
}
}
graph.prim();
graph.toAdjMatrix();
graph.findDepth();
int nofquerries;
infile>>nofquerries;
ofstream myfile;
myfile.open (argv[2]);
for(int i = 0 ; i < nofquerries; ++i){
int x1,x2,y1,y2;
infile>>x1>>x2>>y1>>y2;
myfile<<graph.findDistance((x1-1)*M+x2-1,(y1-1)*M+y2-1)<<endl;
}
return 0;
}