#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"
const int maxn = 1e3 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 30;
const int P = 31;
long long get_distance(int X, int Y);
int n;
ll d[maxn][maxn];
vector<pii> ans;
int r;
void calc(vector<int> v){
random_shuffle(v.begin(), v.end());
random_shuffle(v.begin(), v.end());
random_shuffle(v.begin(), v.end());
random_shuffle(v.begin(), v.end());
r = v[0];
for(int i: v){
if(i != r) d[r][i] = get_distance(r, i);
}
sort(v.begin(), v.end(), [](int i, int j){
return d[r][i] < d[r][j];
});
vector<vector<int>> to;
for(int i: v){
if(i == r) continue;
bool ok = 1;
for(int j = 0; j < to.size(); j++){
if(j == 2 || d[r][to[j][0]] + get_distance(to[j][0], i) == d[r][i]){
to[j].push_back(i);
ok = 0; break;
}
}
if(ok) to.push_back({i});
}
for(auto s: to){
ans.push_back({r, s[0]});
}
for(auto s: to){
calc(s);
}
}
void find_roads(int N, int Q, int A[], int B[], int W[]){
srand(time(0));
n = N;
vector<int> v;
for(int i = 1; i <= n; i++){
v.push_back(i);
}
calc(v);
for(int i = 0; i < n - 1; i++){
A[i] = ans[i].first;
B[i] = ans[i].second;
W[i] = d[A[i]][B[i]];
}
}
Compilation message
citymapping.cpp: In function 'void calc(std::vector<int>)':
citymapping.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int j = 0; j < to.size(); j++){
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9048 KB |
Correct: 24840 out of 500000 queries used. |
2 |
Correct |
6 ms |
9140 KB |
Correct: 44196 out of 500000 queries used. |
3 |
Correct |
14 ms |
9820 KB |
Correct: 154558 out of 500000 queries used. |
4 |
Correct |
7 ms |
9052 KB |
Correct: 71741 out of 500000 queries used. |
5 |
Correct |
9 ms |
9308 KB |
Correct: 76818 out of 500000 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9048 KB |
Correct: 24840 out of 500000 queries used. |
2 |
Correct |
6 ms |
9140 KB |
Correct: 44196 out of 500000 queries used. |
3 |
Correct |
14 ms |
9820 KB |
Correct: 154558 out of 500000 queries used. |
4 |
Correct |
7 ms |
9052 KB |
Correct: 71741 out of 500000 queries used. |
5 |
Correct |
9 ms |
9308 KB |
Correct: 76818 out of 500000 queries used. |
6 |
Correct |
4 ms |
9052 KB |
Correct: 25162 out of 500000 queries used. |
7 |
Correct |
6 ms |
9048 KB |
Correct: 42147 out of 500000 queries used. |
8 |
Correct |
13 ms |
9564 KB |
Correct: 129523 out of 500000 queries used. |
9 |
Correct |
17 ms |
9820 KB |
Correct: 171840 out of 500000 queries used. |
10 |
Correct |
10 ms |
9312 KB |
Correct: 69112 out of 500000 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
8792 KB |
Too many calls to get_distance(). |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
8792 KB |
Too many calls to get_distance(). |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9048 KB |
Correct: 24840 out of 500000 queries used. |
2 |
Correct |
6 ms |
9140 KB |
Correct: 44196 out of 500000 queries used. |
3 |
Correct |
14 ms |
9820 KB |
Correct: 154558 out of 500000 queries used. |
4 |
Correct |
7 ms |
9052 KB |
Correct: 71741 out of 500000 queries used. |
5 |
Correct |
9 ms |
9308 KB |
Correct: 76818 out of 500000 queries used. |
6 |
Correct |
4 ms |
9052 KB |
Correct: 25162 out of 500000 queries used. |
7 |
Correct |
6 ms |
9048 KB |
Correct: 42147 out of 500000 queries used. |
8 |
Correct |
13 ms |
9564 KB |
Correct: 129523 out of 500000 queries used. |
9 |
Correct |
17 ms |
9820 KB |
Correct: 171840 out of 500000 queries used. |
10 |
Correct |
10 ms |
9312 KB |
Correct: 69112 out of 500000 queries used. |
11 |
Incorrect |
3 ms |
8792 KB |
Too many calls to get_distance(). |
12 |
Halted |
0 ms |
0 KB |
- |