-
Notifications
You must be signed in to change notification settings - Fork 0
/
id0082.c
46 lines (36 loc) · 1.1 KB
/
id0082.c
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
// Licensed under the MIT License.
// Path Sum: Three Ways
#include <limits.h>
#include "../lib/grid_neighbor_iterator.h"
#include "../lib/euler.h"
#include "../lib/priority_queue.h"
int main(void)
{
char lineBuffer[512];
int minDistance = INT_MAX;
struct GridGraph grid;
struct Coordinate s = { 0 };
struct Coordinate source = { 0 };
clock_t start = clock();
euler_ok(grid_graph(&grid, 80, 80));
grid_graph_deserialize(&grid, stdin, lineBuffer, sizeof lineBuffer);
struct Coordinate t =
{
.j = grid.n - 1
};
for (s.i = 0; s.i < grid.m; s.i++)
{
grid_min_path(&grid, &s, DIRECTIONS_ALL & ~DIRECTIONS_LEFT);
for (t.i = 0; t.i < grid.n; t.i++)
{
if (grid.edges[t.i * grid.m + t.j].distance < minDistance)
{
source = s;
minDistance = grid.edges[t.i * grid.m + t.j].distance;
}
}
}
int sourceWeight = grid.edges[source.i * grid.m + source.j].weight;
finalize_grid_graph(&grid);
return euler_submit(82, sourceWeight + minDistance, start);
}