#include "citymapping.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define ll long long
#define pb push_back
#define ss second
#define ff first
using namespace std;
vector<int> p(1e3 + 1);
int find(int x) {
if(x == p[x]) return x;
return p[x] = find(p[x]);
}
vector<pair<ll, pii> > mst(int N) {
vector<pair<ll, pii> > path, res;
for(int i = 1; i <= N; i++) {
for(int j = i + 1; j <= N; j++) {
ll ans = get_distance(i, j);
path.pb({ans, {i, j}});
}
}
sort(path.begin(), path.end());
iota(p.begin(), p.end(), 0);
for(auto el : path) {
int a = el.ss.ff, b = el.ss.ss;
ll c = el.ff;
int ap = find(a), bp = find(b);
if(ap == bp) continue;
p[bp] = ap;
res.pb(el);
}
return res;
}
void find_roads(int N, int Q, int A[], int B[], int W[]) {
if(N == 50000) {
vector<pair<ll, pii> > paths = mst(N);
for(int i = 0; i < paths.size(); i++) {
A[i] = paths[i].ss.ff;
B[i] = paths[i].ss.ss;
W[i] = paths[i].ff;
}
} else {
vector<pair<ll, int> > paths;
for(int i = 2; i <= N; i++) {
paths.pb({get_distance(1, i), i});
}
sort(paths.rbegin(), paths.rend());
int f = paths[0].ss;
paths.clear();
for(int i = 1; i <= N; i++) {
if(f != i)
paths.pb({get_distance(f, i), i});
}
sort(paths.begin(), paths.end());
ll temp = 0, last = f;
for(int i = 0; i < N - 1; i++) {
A[i] = last;
B[i] = paths[i].ss;
last = paths[i].ss;
W[i] = paths[i].ff - temp;
temp = paths[i].ff;
// cout << A[i] << " to " << B[i] << " " << W[i] << "\n";
}
}
return;
}
Compilation message
citymapping.cpp: In function 'std::vector<std::pair<long long int, std::pair<int, int> > > mst(int)':
citymapping.cpp:29:6: warning: unused variable 'c' [-Wunused-variable]
29 | ll c = el.ff;
| ^
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < paths.size(); i++) {
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Correct: 1996 out of 500000 queries used. |
2 |
Incorrect |
2 ms |
468 KB |
Reported list of edges differ from actual. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Correct: 1996 out of 500000 queries used. |
2 |
Incorrect |
2 ms |
468 KB |
Reported list of edges differ from actual. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Correct: 1980 out of 12000 queries used. |
2 |
Correct |
1 ms |
468 KB |
Correct: 1984 out of 12000 queries used. |
3 |
Correct |
1 ms |
468 KB |
Correct: 1998 out of 12000 queries used. |
4 |
Correct |
1 ms |
464 KB |
Correct: 1984 out of 12000 queries used. |
5 |
Correct |
1 ms |
468 KB |
Correct: 1980 out of 12000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Correct: 1980 out of 12000 queries used. |
2 |
Correct |
1 ms |
468 KB |
Correct: 1984 out of 12000 queries used. |
3 |
Correct |
1 ms |
468 KB |
Correct: 1998 out of 12000 queries used. |
4 |
Correct |
1 ms |
464 KB |
Correct: 1984 out of 12000 queries used. |
5 |
Correct |
1 ms |
468 KB |
Correct: 1980 out of 12000 queries used. |
6 |
Correct |
2 ms |
468 KB |
Correct: 1994 out of 12000 queries used. |
7 |
Correct |
2 ms |
468 KB |
Correct: 1990 out of 12000 queries used. |
8 |
Correct |
2 ms |
468 KB |
Correct: 1998 out of 12000 queries used. |
9 |
Correct |
2 ms |
468 KB |
Correct: 1992 out of 12000 queries used. |
10 |
Correct |
2 ms |
516 KB |
Correct: 1986 out of 12000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Correct: 1996 out of 500000 queries used. |
2 |
Incorrect |
2 ms |
468 KB |
Reported list of edges differ from actual. |
3 |
Halted |
0 ms |
0 KB |
- |