This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 5003;
int n;
int ans[N][N];
int qry(int x, int y)
{
if (ans[x][y] != -1)
return ans[x][y];
return ans[x][y] = ans[y][x] = getDistance(x, y);
}
bool c[N];
int getnext(int s, int location[], int stype[])
{
int minu = N * 5;
int minx;
for (int x = 0; x < n; ++x)
{
if (s == x)
continue;
if (qry(s, x) < minu)
{
minu = qry(s, x);
minx = x;
}
}
if (stype[s] == 1)
{
stype[minx] = 2;
location[minx] = location[s] + qry(s, minx);
}
else
{
stype[minx] = 1;
location[minx] = location[s] - qry(s, minx);
}
if (!c[minx])
return minx;
int minuu = N * 5;
int minxx;
for (int x = 0; x < n; ++x)
{
if (c[x])
continue;
if (qry(s, x) < qry(minx, x))
{
if (qry(s, x) < minuu)
{
minuu = qry(s, x);
minxx = x;
}
}
}
if (minuu == N * 5)
return -1;
if (stype[s] == 1)
{
stype[minxx] = 2;
location[minxx] = location[s] + qry(s, minxx);
}
else
{
stype[minxx] = 1;
location[minxx] = location[s] - qry(s, minxx);
}
return minxx;
}
void dfs(int x, int location[], int stype[])
{
c[x] = true;
while (1)
{
int h = getnext(x, location, stype);
if (h == -1)
break;
dfs(h, location, stype);
}
}
void findLocation(int N_, int first, int location[], int stype[])
{
n = N_;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if (i == j)
continue;
ans[i][j] = -1;
}
}
location[0] = first;
stype[0] = 1;
dfs(0, location, stype);
}
Compilation message (stderr)
rail.cpp: In function 'int getnext(int, int*, int*)':
rail.cpp:17:17: warning: 'minx' may be used uninitialized in this function [-Wmaybe-uninitialized]
17 | if (ans[x][y] != -1)
| ~~~~~~~~^
rail.cpp:26:9: note: 'minx' was declared here
26 | int minx;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |