#include <bits/stdc++.h>
#include "wombats.h"
using namespace std;
int r, c;
int h[5000][200], v[5000][200];
int dists[1000000];
bool visited[1000000];
priority_queue<pair<int, int> > q;
vector<pair<int, int> > graph[1000000];
void changeH(int p, int q, int w) {
for (int i = 0; i < graph[c*p+q].size(); i++)
{
if (graph[c*p+q][i].first == c*p+q+1)
{
//cout << "Change H part 1:" << graph[c*p+q][i].second << "\n";
graph[c*p+q][i].second = w;
//cout << "Changed to " << graph[c*p+q][i].second << "\n";
}
}
for (int i = 0; i < graph[c*p+q+1].size(); i++)
{
if (graph[c*p+q+1][i].first == c*p+q)
{
//cout << "Change H part 2:" << graph[c*p+q+1][i].second << "\n";
graph[c*p+q+1][i].second = w;
//cout << "Changed to " << graph[c*p+q+1][i].second << "\n";
}
}
}
void changeV(int p, int q, int w){
for (int i = 0; i < graph[i*p+q].size(); i++)
{
if (graph[c*p+q][i].first == c*p+ c + q)
{
//cout << "Change V: " << graph[c*p+q][i].second << "\n";
graph[c*p+q][i].second = w;
//cout << "Changed to " << graph[c*p+q][i].second << "\n";
}
}
}
void init(int R, int C, int H[][3], int V[][4]) {
r = R;
c = C;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c-1; j++)
{
graph[i * c + j].push_back({i*c+j+1, H[i][j]});
graph[i*c + j+1].push_back({i*c+j, H[i][j]});
//cout << "Constructing graph\n";
}
}
for (int i = 0; i < r-1; i++)
{
for (int j = 0; j < c; j++)
{
graph[i*c+j].push_back({i*c + c + j,V[i][j]});
//cout << "Constructing graph\n";
}
}
}
int escape(int v1, int v2) {
int startNode = v1;
int endNode = c*(r-1)+v2;
//cout << "Going from " << startNode << " to " << endNode << "\n";
for (int i = 0; i < r * c; i++)
{
dists[i] = 1000000000;
visited[i] = false;
}
q.push({0, startNode});
dists[startNode] = 0;
while (!q.empty())
{
//cout << "in BFS\n";
int dist = q.top().first;
int node = q.top().second;
//cout << "At node " << node << " at dist " << dist << "\n";
q.pop();
if (!visited[node])
{
visited[node] = true;
dists[node] = min(-dist, dists[node]);
for (auto i : graph[node])
{
if (!visited[i.first])
{
q.push({dist-i.second, i.first});
//cout << "Pushing " << i.first << " at dist " << dist-i.second << "\n";
}
}
}
}
return dists[endNode];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
wombats.cpp: In function 'void changeH(int, int, int)':
wombats.cpp:13:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < graph[c*p+q].size(); i++)
~~^~~~~~~~~~~~~~~~~~~~~
wombats.cpp:22:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < graph[c*p+q+1].size(); i++)
~~^~~~~~~~~~~~~~~~~~~~~~~
wombats.cpp: In function 'void changeV(int, int, int)':
wombats.cpp:35:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < graph[i*p+q].size(); i++)
~~^~~~~~~~~~~~~~~~~~~~~
/tmp/ccWJSBc3.o: In function `main':
grader.c:(.text.startup+0x103): undefined reference to `init'
collect2: error: ld returned 1 exit status