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 "citymapping.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1000;
static ll dst[MAXN + 1][MAXN + 1];
static int qpos = 0;
static mt19937 rng;
inline ll get(int a, int b) {
if(a == b) return 0;
if(dst[a][b] == -1) {
dst[a][b] = dst[b][a] = get_distance(a, b);
}
return dst[a][b];
}
inline int myrand(int md) {
return (1LL * (1LL * rand() << 15) ^ rand()) % md;
}
void solve(vector <int> &nodes, int *a, int *b, int *w) {
shuffle(nodes.begin(), nodes.end(), rng);
int nod = nodes[0];
vector < pair <ll, int> > cur;
for(auto it : nodes) {
if(it != nod) {
cur.push_back({get(nod, it), it});
}
}
sort(cur.begin(), cur.end());
vector < vector <int> > comps;
for(auto it : cur) {
int j = 0;
while(j < min(2, (int)comps.size()) && get(nod, it.second) != get(nod, comps[j][0]) + get(comps[j][0], it.second)) {
j++;
}
if(comps.size() == j) {
comps.push_back(vector <int>());
}
comps[j].push_back(it.second);
if(comps[j].size() == 1) {
a[qpos] = nod;
b[qpos] = it.second;
w[qpos] = it.first;
qpos++;
//cerr << nod << " " << it.second << " " << it.first << "\n";
}
}
for(auto &it : comps) {
solve(it, a, b, w);
}
}
void find_roads(int N, int Q, int A[], int B[], int W[]) {
memset(dst, -1, sizeof(dst));
srand(time(NULL));
vector <int> nodes(N);
iota(nodes.begin(), nodes.end(), 1);
solve(nodes, A, B, W);
/*cerr << qpos << "\n";
for(i = 0; i < n - 1; i++) {
}*/
return ;
}
Compilation message (stderr)
citymapping.cpp: In function 'void solve(std::vector<int>&, int*, int*, int*)':
citymapping.cpp:44:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(comps.size() == j) {
~~~~~~~~~~~~~^~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |