#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
ll a,b,w;
bool operator <(const node& rhs) const{
return w < rhs.w;
}
};
vector <ll> id;
ll find(ll i){
if (id[i] < 0) return i;
return id[i] = find(id[i]);
}
void unio(ll i,ll j){
ll a = find(i);
ll b = find(j);
if (a == b) return;
if (id[b] < id[a]) swap(a,b);
id[a] += id[b];
id[b] = a;
}
void find_roads(int n, int q, int a[], int b[], int w[]) {
vector <node> arr;
if (q == 12000){
for (int z=2;z<=n;z++){
node temp;
temp.a = 1; temp.b = z; temp.w = get_distance(1,z);
arr.push_back(temp);
}
sort(arr.begin(),arr.end());
ll left = 0;
ll right = 0;
ll leftpos = 1;
ll rightpos = 1;
ll c = 0;
for (int z=0;z<n-1;z++){
ll temp = get_distance(leftpos,arr[z].b);
if (left+temp == arr[z].w){
left += temp;
a[c] = leftpos;
b[c] = arr[z].b;
w[c] = temp;
leftpos = arr[z].b;
c++;
continue;
}
temp = get_distance(rightpos,arr[z].b);
if (right+temp == arr[z].w){
right += temp;
a[c] = leftpos;
b[c] = arr[z].b;
w[c] = temp;
rightpos = arr[z].b;
c++;
continue;
}
}
return;
}
for (int z=1;z<=n;z++){
for (int x=z+1;x<=n;x++){
node temp;
temp.a = z; temp.b = x; temp.w = get_distance(z,x);
arr.push_back(temp);
}
}
id.resize(n+1,-1);
sort(arr.begin(),arr.end());
vector <ll> count(n+1,0);
ll c = 0;
for (int z=0;z<arr.size();z++){
if (count[arr[z].a] >= 3 || count[arr[z].b] >= 3) continue;
ll i = find(arr[z].a);
ll j = find(arr[z].b);
if (i == j) continue;
unio(i,j);
a[c] = arr[z].a;
b[c] = arr[z].b;
w[c] = arr[z].w;
count[arr[z].a]++;
count[arr[z].b]++;
c++;
}
return;
}
Compilation message
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:80:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int z=0;z<arr.size();z++){
~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
12888 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
104 ms |
13024 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
85 ms |
12888 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
79 ms |
12940 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
98 ms |
12896 KB |
Correct: 498501 out of 500000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
12888 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
104 ms |
13024 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
85 ms |
12888 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
79 ms |
12940 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
98 ms |
12896 KB |
Correct: 498501 out of 500000 queries used. |
6 |
Correct |
113 ms |
13016 KB |
Correct: 495510 out of 500000 queries used. |
7 |
Correct |
119 ms |
12888 KB |
Correct: 497503 out of 500000 queries used. |
8 |
Correct |
117 ms |
12888 KB |
Correct: 497503 out of 500000 queries used. |
9 |
Correct |
107 ms |
12888 KB |
Correct: 495510 out of 500000 queries used. |
10 |
Correct |
119 ms |
12916 KB |
Correct: 496506 out of 500000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
12888 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
104 ms |
13024 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
85 ms |
12888 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
79 ms |
12940 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
98 ms |
12896 KB |
Correct: 498501 out of 500000 queries used. |
6 |
Correct |
113 ms |
13016 KB |
Correct: 495510 out of 500000 queries used. |
7 |
Correct |
119 ms |
12888 KB |
Correct: 497503 out of 500000 queries used. |
8 |
Correct |
117 ms |
12888 KB |
Correct: 497503 out of 500000 queries used. |
9 |
Correct |
107 ms |
12888 KB |
Correct: 495510 out of 500000 queries used. |
10 |
Correct |
119 ms |
12916 KB |
Correct: 496506 out of 500000 queries used. |
11 |
Incorrect |
3 ms |
504 KB |
Reported list of edges differ from actual. |
12 |
Halted |
0 ms |
0 KB |
- |